Skip to content

Commit

Permalink
v1.12 release
Browse files Browse the repository at this point in the history
  • Loading branch information
twistedpair committed Jul 20, 2022
1 parent 0e77ffd commit 0387067
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 45 deletions.
18 changes: 15 additions & 3 deletions lib/src/mablApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ class MablApiClient {
};
this.httpClient = axios_1.default.create(config);
}
static throwHumanizedError(response) {
switch (response.status) {
case 401:
throw new Error(`Unauthorized API error, are you sure you passed the correct API key? Is the key "enabled"?`);
case 403:
throw new Error(`Forbidden API error, are you sure you used a "CI/CD Integration" type API key? Ensure this key is for the same workspace you're testing.`);
case 404:
throw new Error(`Not Found API error, please ensure any environment or application IDs in your Action config are correct.`);
default:
throw new Error(`[${response.status} - ${response.statusText}]`);
}
}
makeGetRequest(url) {
return __awaiter(this, void 0, void 0, function* () {
return (0, async_retry_1.default)(() => __awaiter(this, void 0, void 0, function* () {
Expand All @@ -43,7 +55,7 @@ class MablApiClient {
timeout: GET_REQUEST_TIMEOUT_MILLIS,
});
if (((_a = response.status) !== null && _a !== void 0 ? _a : 400) >= 400) {
throw new Error(`[${response.status} - ${response.statusText}]`);
MablApiClient.throwHumanizedError(response);
}
return response.data;
}), {
Expand All @@ -68,7 +80,7 @@ class MablApiClient {
getApplication(id) {
return __awaiter(this, void 0, void 0, function* () {
try {
return yield this.makeGetRequest(`${this.baseUrl}/v1/applications/${id}`);
return yield this.makeGetRequest(`${this.baseUrl}/applications/${id}`);
}
catch (error) {
throw new Error(`failed to get mabl application (${id}) from the API ${error}`);
Expand All @@ -78,7 +90,7 @@ class MablApiClient {
getEnvironment(id) {
return __awaiter(this, void 0, void 0, function* () {
try {
return yield this.makeGetRequest(`${this.baseUrl}/v1/environments/${id}`);
return yield this.makeGetRequest(`${this.baseUrl}/environments/${id}`);
}
catch (error) {
throw new Error(`failed to get mabl environment (${id}) from the API ${error}`);
Expand Down
40 changes: 40 additions & 0 deletions lib/test/suite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,46 @@ describe('GitHub Action tests', () => {
setGithubInput(constants_1.ActionInputs.ApplicationId, 'BAZ');
expect((0, src_1.optionalInput)(constants_1.ActionInputs.ApplicationId)).toEqual('BAZ');
});
it('humanizes 403 errors', () => {
expect(() => mablApiClient_1.MablApiClient.throwHumanizedError({
status: 403,
statusText: 'This is an error',
config: {},
headers: {},
data: 10,
request: {}
})).toThrow("Forbidden API error, are you sure you used a \"CI/CD Integration\" type API key? Ensure this key is for the same workspace you're testing.");
});
it('humanizes 401 errors', () => {
expect(() => mablApiClient_1.MablApiClient.throwHumanizedError({
status: 401,
statusText: 'This is an error',
config: {},
headers: {},
data: 10,
request: {}
})).toThrow('Unauthorized API error, are you sure you passed the correct API key? Is the key "enabled"?');
});
it('humanizes 404 errors', () => {
expect(() => mablApiClient_1.MablApiClient.throwHumanizedError({
status: 404,
statusText: 'This is an error',
config: {},
headers: {},
data: 10,
request: {}
})).toThrow('Not Found API error, please ensure any environment or application IDs in your Action config are correct.');
});
it('humanizes non-specific errors', () => {
expect(() => mablApiClient_1.MablApiClient.throwHumanizedError({
status: 500,
statusText: 'This is an error',
config: {},
headers: {},
data: 10,
request: {}
})).toThrow('[500 - This is an error]');
});
it('builds the request correctly with all options', () => {
const expected = {
environment_id: 'env',
Expand Down
14 changes: 13 additions & 1 deletion node_modules/moment/CHANGELOG.md

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

5 changes: 3 additions & 2 deletions node_modules/moment/dist/locale/sr-cyrl.js

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

5 changes: 3 additions & 2 deletions node_modules/moment/dist/locale/sr.js

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

6 changes: 3 additions & 3 deletions node_modules/moment/dist/moment.js

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

5 changes: 3 additions & 2 deletions node_modules/moment/locale/sr-cyrl.js

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

5 changes: 3 additions & 2 deletions node_modules/moment/locale/sr.js

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

10 changes: 6 additions & 4 deletions node_modules/moment/min/locales.js

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

2 changes: 1 addition & 1 deletion node_modules/moment/min/locales.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node_modules/moment/min/locales.min.js.map

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions node_modules/moment/min/moment-with-locales.js

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

2 changes: 1 addition & 1 deletion node_modules/moment/min/moment-with-locales.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node_modules/moment/min/moment-with-locales.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node_modules/moment/min/moment.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node_modules/moment/min/moment.min.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions node_modules/moment/moment.js

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

8 changes: 4 additions & 4 deletions node_modules/moment/package.json

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

2 changes: 1 addition & 1 deletion node_modules/moment/src/lib/create/from-string.js

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

5 changes: 3 additions & 2 deletions node_modules/moment/src/locale/sr-cyrl.js

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

Loading

0 comments on commit 0387067

Please sign in to comment.