diff --git a/src/jira/client/axios.test.ts b/src/jira/client/axios.test.ts index 05659f156c..180a671709 100644 --- a/src/jira/client/axios.test.ts +++ b/src/jira/client/axios.test.ts @@ -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."); }); }); diff --git a/src/jira/client/axios.ts b/src/jira/client/axios.ts index cfed24de41..4380d79f63 100644 --- a/src/jira/client/axios.ts +++ b/src/jira/client/axios.ts @@ -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: @@ -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; } } }