@octokit/request
Advanced tools
Comparing version 2.0.0 to 2.0.1
module.exports = class HttpError extends Error { | ||
constructor (message, code) { | ||
constructor (message, code, headers) { | ||
super(message) | ||
@@ -13,3 +13,4 @@ | ||
this.code = code | ||
this.headers = headers | ||
} | ||
} |
@@ -55,3 +55,11 @@ 'use strict' | ||
.then(message => { | ||
throw new HttpError(message, status, headers) | ||
const error = new HttpError(message, status, headers) | ||
try { | ||
Object.assign(error, JSON.parse(error.message)) | ||
} catch (e) { | ||
// ignore, see octokit/rest.js#684 | ||
} | ||
throw error | ||
}) | ||
@@ -58,0 +66,0 @@ } |
{ | ||
"name": "@octokit/request", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
@@ -322,2 +322,36 @@ const chai = require('chai') | ||
}) | ||
it('422 error with details', () => { | ||
mockable.fetch = fetchMock.sandbox() | ||
.post('https://api.github.com/repos/octocat/hello-world/labels', { | ||
status: 422, | ||
headers: { | ||
'Content-Type': 'application/json; charset=utf-8', | ||
'X-Foo': 'bar' | ||
}, | ||
body: { | ||
message: 'Validation Failed', | ||
errors: [ | ||
{ | ||
resource: 'Label', | ||
code: 'invalid', | ||
field: 'color' | ||
} | ||
], | ||
documentation_url: 'https://developer.github.com/v3/issues/labels/#create-a-label' | ||
} | ||
}) | ||
return octokitRequest('POST /repos/octocat/hello-world/labels', { | ||
name: 'foo', | ||
color: 'invalid' | ||
}) | ||
.catch(error => { | ||
expect(error.code).to.equal(422) | ||
expect(error.headers['x-foo']).to.equal('bar') | ||
expect(error.documentation_url).to.equal('https://developer.github.com/v3/issues/labels/#create-a-label') | ||
expect(error.errors).to.deep.equal([{ resource: 'Label', code: 'invalid', field: 'color' }]) | ||
}) | ||
}) | ||
}) |
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
35299
487