@octokit/request
Advanced tools
Comparing version 2.0.1 to 2.1.0
module.exports = class HttpError extends Error { | ||
constructor (message, code, headers) { | ||
constructor (message, statusCode, headers) { | ||
super(message) | ||
@@ -12,5 +12,11 @@ | ||
this.name = 'HttpError' | ||
this.code = code | ||
this.status = statusCode | ||
Object.defineProperty(this, 'code', { | ||
get () { | ||
console.warn('`error.code` is deprecated, use `error.status`.') | ||
return statusCode | ||
} | ||
}) | ||
this.headers = headers | ||
} | ||
} |
{ | ||
"name": "@octokit/request", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
@@ -162,3 +162,3 @@ const chai = require('chai') | ||
.catch(error => { | ||
expect(error.code).to.equal(404) | ||
expect(error.status).to.equal(404) | ||
}) | ||
@@ -227,3 +227,3 @@ }) | ||
.catch(error => { | ||
expect(error.code).to.equal(304) | ||
expect(error.status).to.equal(304) | ||
}) | ||
@@ -245,3 +245,3 @@ }) | ||
.catch(error => { | ||
expect(error.code).to.equal(404) | ||
expect(error.status).to.equal(404) | ||
}) | ||
@@ -285,3 +285,3 @@ }) | ||
.catch(error => { | ||
expect(error.code).to.equal(500) | ||
expect(error.status).to.equal(500) | ||
}) | ||
@@ -354,3 +354,3 @@ }) | ||
.catch(error => { | ||
expect(error.code).to.equal(422) | ||
expect(error.status).to.equal(422) | ||
expect(error.headers['x-foo']).to.equal('bar') | ||
@@ -361,2 +361,19 @@ expect(error.documentation_url).to.equal('https://developer.github.com/v3/issues/labels/#create-a-label') | ||
}) | ||
it('error.code (deprecated)', () => { | ||
mockable.fetch = fetchMock.sandbox() | ||
.get('path:/orgs/nope', 404) | ||
return octokitRequest('GET /orgs/:org', { | ||
org: 'nope' | ||
}) | ||
.then(() => { | ||
throw new Error('should not resolve') | ||
}) | ||
.catch(error => { | ||
expect(error.code).to.equal(404) | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35838
506