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] authored and manstis committed Mar 11, 2024
1 parent fbfc9b0 commit 89d279e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
14 changes: 9 additions & 5 deletions src/features/lightspeed/handleApiError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ 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") {
return 'Something in your editor content has caused your inline suggestion request to be blocked. \n' +
'Please open a ticket with Red Hat support and include the content of your editor up to the \n' +
'line and column where you requested a suggestion.';
if (
(err?.response?.headers["server"] || "").toLowerCase() === "cloudfront"
) {
return (
"Something in your editor content has caused your inline suggestion request to be blocked. \n" +
"Please open a ticket with Red Hat support and include the content of your editor up to the \n" +
"line and column where you requested a suggestion."
);
} else {
const responseErrorData = <AxiosError<{ message?: string }>>(
err?.response?.data
Expand Down Expand Up @@ -57,7 +61,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 89d279e

Please sign in to comment.