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

Remove unnecessary iiafes #212

Merged
merged 3 commits into from
Sep 10, 2020
Merged
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
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