Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #294: Make AirtableError extend Error #402

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions build/airtable.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,29 @@ module.exports = AbortController;

},{"abort-controller":20,"abortcontroller-polyfill/dist/cjs-ponyfill":19}],2:[function(require,module,exports){
"use strict";
var AirtableError = /** @class */ (function () {
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var AirtableError = /** @class */ (function (_super) {
__extends(AirtableError, _super);
function AirtableError(error, message, statusCode) {
this.error = error;
this.message = message;
this.statusCode = statusCode;
var _this = _super.call(this, message) || this;
_this.name = 'AirtableError';
_this.error = error;
_this.message = message;
_this.statusCode = statusCode;
_this.toString = AirtableError.prototype.toString.bind(_this);
return _this;
}
AirtableError.prototype.toString = function () {
return [
Expand All @@ -35,7 +53,7 @@ var AirtableError = /** @class */ (function () {
].join('');
};
return AirtableError;
}());
}(Error));
module.exports = AirtableError;

},{}],3:[function(require,module,exports){
Expand Down
5 changes: 4 additions & 1 deletion src/airtable_error.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
class AirtableError {
class AirtableError extends Error {
error: string;
message: string;
statusCode: number;

constructor(error: string, message: string, statusCode: number) {
super(message);
this.name = 'AirtableError';
this.error = error;
this.message = message;
this.statusCode = statusCode;
this.toString = AirtableError.prototype.toString.bind(this);
}

toString(): string {
Expand Down
10 changes: 10 additions & 0 deletions test/airtable_error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ describe('AirtableError', function() {
expect(error.toString()).toEqual(expect.stringContaining('404'));
});
});

it('has a stacktrace', function() {
var error = new AirtableError('TEST_ERROR', 'A test error', 400);
expect(error.stack).toEqual(expect.stringContaining('airtable_error.test.js'));
});

it('has a name', function() {
var error = new AirtableError('TEST_ERROR', 'A test error', 400);
expect(error.name).toEqual('AirtableError');
});
});
34 changes: 17 additions & 17 deletions test/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ describe('Base', function() {
res.status(401).json({});
});

return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'AUTHENTICATION_REQUIRED',
message: expect.any(String),
statusCode: 401,
Expand All @@ -285,7 +285,7 @@ describe('Base', function() {
.end();
});

return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'NOT_AUTHORIZED',
message: expect.any(String),
statusCode: 403,
Expand All @@ -299,7 +299,7 @@ describe('Base', function() {
.end();
});

return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'NOT_FOUND',
message: expect.any(String),
statusCode: 404,
Expand All @@ -315,7 +315,7 @@ describe('Base', function() {
});
});

return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'NOT_FOUND',
message: 'foo bar',
statusCode: 404,
Expand All @@ -329,7 +329,7 @@ describe('Base', function() {
.end();
});

return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'REQUEST_TOO_LARGE',
message: expect.any(String),
statusCode: 413,
Expand All @@ -343,7 +343,7 @@ describe('Base', function() {
.end();
});

return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'UNPROCESSABLE_ENTITY',
message: expect.any(String),
statusCode: 422,
Expand All @@ -359,7 +359,7 @@ describe('Base', function() {
});
});

return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'FOO_BAR',
message: expect.any(String),
statusCode: 422,
Expand All @@ -375,7 +375,7 @@ describe('Base', function() {
});
});

return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'UNPROCESSABLE_ENTITY',
message: 'foo bar',
statusCode: 422,
Expand All @@ -395,7 +395,7 @@ describe('Base', function() {
noRetryIfRateLimited: true,
}).base('app123');

return expect(base.makeRequest()).rejects.toEqual({
return expect(base.makeRequest()).rejects.toMatchObject({
error: 'TOO_MANY_REQUESTS',
message: expect.any(String),
statusCode: 429,
Expand Down Expand Up @@ -425,7 +425,7 @@ describe('Base', function() {
.end();
});

return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'SERVER_ERROR',
message: expect.any(String),
statusCode: 500,
Expand All @@ -439,7 +439,7 @@ describe('Base', function() {
.end();
});

return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'SERVICE_UNAVAILABLE',
message: expect.any(String),
statusCode: 503,
Expand All @@ -453,7 +453,7 @@ describe('Base', function() {
.end();
});

return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'UNEXPECTED_ERROR',
message: expect.any(String),
statusCode: 402,
Expand All @@ -467,7 +467,7 @@ describe('Base', function() {
});
});

return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'FOO_BAR',
message: expect.any(String),
statusCode: 402,
Expand All @@ -481,7 +481,7 @@ describe('Base', function() {
});
});

return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'UNEXPECTED_ERROR',
message: 'foo bar',
statusCode: 402,
Expand All @@ -494,7 +494,7 @@ describe('Base', function() {
res.send('{"foo":');
});

return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'UNEXPECTED_ERROR',
message: expect.any(String),
statusCode: 200,
Expand All @@ -506,7 +506,7 @@ describe('Base', function() {
res.json(['foo', 'bar']);
});

return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'UNEXPECTED_ERROR',
message: expect.any(String),
statusCode: 200,
Expand All @@ -524,7 +524,7 @@ describe('Base', function() {
testExpressApp = env.testExpressApp;
})
.then(function() {
return expect(fakeBase.makeRequest()).rejects.toEqual({
return expect(fakeBase.makeRequest()).rejects.toMatchObject({
error: 'CONNECTION_ERROR',
message: expect.any(String),
statusCode: null,
Expand Down
28 changes: 23 additions & 5 deletions test/test_files/airtable.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,29 @@ module.exports = AbortController;

},{"abort-controller":20,"abortcontroller-polyfill/dist/cjs-ponyfill":19}],2:[function(require,module,exports){
"use strict";
var AirtableError = /** @class */ (function () {
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var AirtableError = /** @class */ (function (_super) {
__extends(AirtableError, _super);
function AirtableError(error, message, statusCode) {
this.error = error;
this.message = message;
this.statusCode = statusCode;
var _this = _super.call(this, message) || this;
_this.name = 'AirtableError';
_this.error = error;
_this.message = message;
_this.statusCode = statusCode;
_this.toString = AirtableError.prototype.toString.bind(_this);
return _this;
}
AirtableError.prototype.toString = function () {
return [
Expand All @@ -35,7 +53,7 @@ var AirtableError = /** @class */ (function () {
].join('');
};
return AirtableError;
}());
}(Error));
module.exports = AirtableError;

},{}],3:[function(require,module,exports){
Expand Down