Skip to content

Commit

Permalink
chore: auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Mar 8, 2024
1 parent 505f2da commit 5f5e50a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/features/lightspeed/handleApiError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export function retrieveError(err: AxiosError): string {
return "Bad Request response. Please try again.";
}
} else if (err?.response?.status === 403) {
if((err?.response?.headers["server"] || "").toLowerCase() === "cloudfront") {
if (
(err?.response?.headers["server"] || "").toLowerCase() === "cloudfront"
) {
return `CloudFront rejected the request. Please contact your administrator.`;
} else {
const responseErrorData = <AxiosError<{ message?: string }>>(
Expand Down Expand Up @@ -55,7 +57,7 @@ export function retrieveError(err: AxiosError): string {
}
} else {
return "User not authorized to access Ansible Lightspeed.";
}
}
}
} else if (err?.response?.status.toString().startsWith("5")) {
return "Ansible Lightspeed encountered an error. Try again after some time.";
Expand Down
13 changes: 10 additions & 3 deletions test/units/lightspeed/handleApiError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { AxiosError, AxiosHeaders } from "axios";
import { retrieveError } from "../../../src/features/lightspeed/handleApiError";
import assert from "assert";

function createError(http_code: number, data = {}, err_headers = {}): AxiosError {
function createError(
http_code: number,
data = {},
err_headers = {}
): AxiosError {
const request = { path: "/wisdom" };
const headers = new AxiosHeaders({
...err_headers,
Expand Down Expand Up @@ -156,12 +160,15 @@ describe("testing the error handling", () => {

it("err Bad Request from CloudFront", () => {
const msg = retrieveError(
createError(403, { data: "Some string from CloudFront." }, { server: "CloudFront" })
createError(
403,
{ data: "Some string from CloudFront." },
{ server: "CloudFront" }
)
);
assert.equal(
msg,
"CloudFront rejected the request. Please contact your administrator."
);
});

});

0 comments on commit 5f5e50a

Please sign in to comment.