mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
fix: sanitize timeout error message
This commit is contained in:
parent
18a5dbe058
commit
66ca109c77
2 changed files with 8 additions and 3 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { isHTTPError, isNetworkError } from "ky";
|
||||
import { isHTTPError, isNetworkError, isTimeoutError } from "ky";
|
||||
|
||||
export function mapHttpStatusToMessage(status: number, data?: unknown): string {
|
||||
if (status === 401) {
|
||||
|
|
@ -36,5 +36,10 @@ export function normalizeApiRequestError(error: Error): Error {
|
|||
return error;
|
||||
}
|
||||
|
||||
if (isTimeoutError(error)) {
|
||||
error.message = "The request timed out. Please try again.";
|
||||
return error;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ describe("normalizeApiRequestError", () => {
|
|||
);
|
||||
});
|
||||
|
||||
it("preserves the original message for timeouts", async () => {
|
||||
it("returns a friendly timeout message", async () => {
|
||||
const fetchImpl = vi.fn((_input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const signal = init?.signal;
|
||||
return new Promise<Response>((_resolve, reject) => {
|
||||
|
|
@ -48,7 +48,7 @@ describe("normalizeApiRequestError", () => {
|
|||
}) as unknown as typeof fetch;
|
||||
|
||||
await expect(createClient(fetchImpl).get(RESOURCE_URL).json()).rejects.toThrow(
|
||||
"Request timed out",
|
||||
"The request timed out. Please try again.",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue