Skip to content

Commit

Permalink
Remove unnecessary iiafes (#212)
Browse files Browse the repository at this point in the history
* Base: Remove unnecessary IIAFEs

* Babel + Istanbul: Cannot count optional chaining operator coverage.

See:
- istanbuljs/istanbuljs#516
- istanbuljs/istanbuljs#516 (comment)

* Rebuild
  • Loading branch information
rwaldron authored and Airtable committed Nov 4, 2020
1 parent 7199492 commit 3779ad4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 50 deletions.
27 changes: 5 additions & 22 deletions build/airtable.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,33 +144,22 @@ var Base = /** @class */ (function () {
return result.toJSON();
};
Base.prototype._checkStatusForError = function (statusCode, body) {
var _a = (body !== null && body !== void 0 ? body : { error: {} }).error, error = _a === void 0 ? {} : _a;
var type = error.type, message = error.message;
if (statusCode === 401) {
return new airtable_error_1.default('AUTHENTICATION_REQUIRED', 'You should provide valid api key to perform this operation', statusCode);
}
else if (statusCode === 403) {
return new airtable_error_1.default('NOT_AUTHORIZED', 'You are not authorized to perform this operation', statusCode);
}
else if (statusCode === 404) {
return (function () {
var message = body && body.error && body.error.message
? body.error.message
: 'Could not find what you are looking for';
return new airtable_error_1.default('NOT_FOUND', message, statusCode);
})();
return new airtable_error_1.default('NOT_FOUND', message !== null && message !== void 0 ? message : 'Could not find what you are looking for', statusCode);
}
else if (statusCode === 413) {
return new airtable_error_1.default('REQUEST_TOO_LARGE', 'Request body is too large', statusCode);
}
else if (statusCode === 422) {
return (function () {
var type = body && body.error && body.error.type
? body.error.type
: 'UNPROCESSABLE_ENTITY';
var message = body && body.error && body.error.message
? body.error.message
: 'The operation cannot be processed';
return new airtable_error_1.default(type, message, statusCode);
})();
return new airtable_error_1.default(type !== null && type !== void 0 ? type : 'UNPROCESSABLE_ENTITY', message !== null && message !== void 0 ? message : 'The operation cannot be processed', statusCode);
}
else if (statusCode === 429) {
return new airtable_error_1.default('TOO_MANY_REQUESTS', 'You have made too many requests in a short period of time. Please retry your request later', statusCode);
Expand All @@ -182,13 +171,7 @@ var Base = /** @class */ (function () {
return new airtable_error_1.default('SERVICE_UNAVAILABLE', 'The service is temporarily unavailable. Please retry shortly.', statusCode);
}
else if (statusCode >= 400) {
return (function () {
var type = body && body.error && body.error.type ? body.error.type : 'UNEXPECTED_ERROR';
var message = body && body.error && body.error.message
? body.error.message
: 'An unexpected error occurred';
return new airtable_error_1.default(type, message, statusCode);
})();
return new airtable_error_1.default(type !== null && type !== void 0 ? type : 'UNEXPECTED_ERROR', message !== null && message !== void 0 ? message : 'An unexpected error occurred', statusCode);
}
else {
return null;
Expand Down
58 changes: 30 additions & 28 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ class Base {
}

_checkStatusForError(statusCode, body) {

const {
error = {}
} = body ?? {error: {}};

const {
type,
message
} = error;

if (statusCode === 401) {
return new AirtableError(
'AUTHENTICATION_REQUIRED',
Expand All @@ -151,27 +161,23 @@ class Base {
statusCode
);
} else if (statusCode === 404) {
return (() => {
const message =
body && body.error && body.error.message
? body.error.message
: 'Could not find what you are looking for';
return new AirtableError('NOT_FOUND', message, statusCode);
})();
return new AirtableError(
'NOT_FOUND',
message ?? 'Could not find what you are looking for',
statusCode
);
} else if (statusCode === 413) {
return new AirtableError('REQUEST_TOO_LARGE', 'Request body is too large', statusCode);
return new AirtableError(
'REQUEST_TOO_LARGE',
'Request body is too large',
statusCode
);
} else if (statusCode === 422) {
return (() => {
const type =
body && body.error && body.error.type
? body.error.type
: 'UNPROCESSABLE_ENTITY';
const message =
body && body.error && body.error.message
? body.error.message
: 'The operation cannot be processed';
return new AirtableError(type, message, statusCode);
})();
return new AirtableError(
type ?? 'UNPROCESSABLE_ENTITY',
message ?? 'The operation cannot be processed',
statusCode
);
} else if (statusCode === 429) {
return new AirtableError(
'TOO_MANY_REQUESTS',
Expand All @@ -191,15 +197,11 @@ class Base {
statusCode
);
} else if (statusCode >= 400) {
return (() => {
const type =
body && body.error && body.error.type ? body.error.type : 'UNEXPECTED_ERROR';
const message =
body && body.error && body.error.message
? body.error.message
: 'An unexpected error occurred';
return new AirtableError(type, message, statusCode);
})();
return new AirtableError(
type ?? 'UNEXPECTED_ERROR',
message ?? 'An unexpected error occurred',
statusCode
);
} else {
return null;
}
Expand Down

0 comments on commit 3779ad4

Please sign in to comment.