Skip to content

Commit

Permalink
ARC-1429: Return 404 if Jira has been renamed. (#1268)
Browse files Browse the repository at this point in the history
* ARC-1429: Return 404 if Jira has been renamed.

* refactor

* change if to else if
  • Loading branch information
atrigueiro authored Jun 16, 2022
1 parent 855df59 commit 951ea56
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/jira/client/axios.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,23 @@ describe("Jira axios instance", () => {
}

expect(error?.status).toEqual(404);
expect(error?.message).toEqual("Error executing Axios Request HTTP 404 - Bad REST path, or Jira instance not found or temporarily suspended.");
expect(error?.message).toEqual("Error executing Axios Request HTTP 404 - Bad REST path, or Jira instance not found, renamed or temporarily suspended.");
});

it("should return 404 from failed request if Jira has been renamed", async () => {
const requestPayload = "TestRequestPayload";
jiraNock.post("/foo/bar", requestPayload).reply(405);
jiraNock.get("/status").reply(302);

let error;
try {
await getAxiosInstance(jiraHost, "secret").post("/foo/bar", requestPayload);
} catch (e) {
error = e;
}

expect(error?.status).toEqual(404);
expect(error?.message).toEqual("Error executing Axios Request HTTP 404 - Bad REST path, or Jira instance not found, renamed or temporarily suspended.");
});

});
7 changes: 5 additions & 2 deletions src/jira/client/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const getJiraErrorMessages = (status: number) => {
case 403:
return "HTTP 403 - The JWT token used does not correspond to an app that defines the jiraDevelopmentTool module, or the app does not define the 'WRITE' scope";
case 404:
return "HTTP 404 - Bad REST path, or Jira instance not found or temporarily suspended.";
return "HTTP 404 - Bad REST path, or Jira instance not found, renamed or temporarily suspended.";
case 413:
return "HTTP 413 - Data is too large. Submit fewer devinfo entities in each payload.";
case 429:
Expand Down Expand Up @@ -147,13 +147,16 @@ const instrumentRequest = (response) => {
const instrumentFailedRequest = (baseURL: string, logger: Logger) => {
return async (error: AxiosError) => {
instrumentRequest(error?.response);
if (error.response?.status === 503) {
if (error.response?.status === 503 || error.response?.status === 405) {
try {
await axios.get("/status", { baseURL });
} catch (e) {
if (e.response.status === 503) {
logger.info(`503 from Jira: Jira instance '${baseURL}' has been deactivated, is suspended or does not exist. Returning 404 to our application.`);
error.response.status = 404;
} else if (e.response.status === 302) {
logger.info(`405 from Jira: Jira instance '${baseURL}' has been renamed. Returning 404 to our application.`);
error.response.status = 404;
}
}
}
Expand Down

0 comments on commit 951ea56

Please sign in to comment.