Skip to content

Commit

Permalink
Make AlksError extend Error
Browse files Browse the repository at this point in the history
  • Loading branch information
pofallon committed Jan 15, 2019
1 parent 911ba53 commit bb242d7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"mocha": true
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2018
"sourceType": "module"
},
"extends": "eslint:recommended",
"rules": {
Expand Down
15 changes: 11 additions & 4 deletions dist/alks.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,17 @@ var alks = (function () {
})
};
var pick = function (obj, props) { return props.reduce(function (a, e) { return (a[e] = obj[e], a); }, {}); };
var AlksError = function (response, json) { return (Object.assign({}, {name: 'AlksError',
message: response.statusText,
status: response.status},
json)); };
var AlksError = (function (Error) {
function AlksError(response, json) {
Error.call(this, response.statusText);
this.status = response.status;
Object.assign(this, json);
}
if ( Error ) AlksError.__proto__ = Error;
AlksError.prototype = Object.create( Error && Error.prototype );
AlksError.prototype.constructor = AlksError;
return AlksError;
}(Error));
var alks$1 = new alks();

return alks$1;
Expand Down
2 changes: 1 addition & 1 deletion dist/alks.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions lib/alks.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,13 @@ class alks {

const pick = (obj, props) => props.reduce((a, e) => (a[e] = obj[e], a), {});

const AlksError = (response, json) => ({
name: 'AlksError',
message: response.statusText,
status: response.status,
...json
});
class AlksError extends Error {
constructor(response, json) {
super(response.statusText);
this.status = response.status;
Object.assign(this, json);
}
}

var alks$1 = new alks();

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alks.js",
"version": "1.0.0",
"version": "1.0.1",
"description": "JavaScript client for the ALKS API, usable in both modern browsers and node.js",
"main": "lib/alks.node.js",
"scripts": {
Expand Down
13 changes: 7 additions & 6 deletions src/alks.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,12 @@ class alks {

const pick = (obj, props) => props.reduce((a, e) => (a[e] = obj[e], a), {})

const AlksError = (response, json) => ({
name: 'AlksError',
message: response.statusText,
status: response.status,
...json
})
class AlksError extends Error {
constructor(response, json) {
super(response.statusText)
this.status = response.status
Object.assign(this, json)
}
}

export default new alks()

0 comments on commit bb242d7

Please sign in to comment.