OpenPanel/packages/supabase/test/utils/handleError.spec.ts
2024-02-05 10:23:04 +01:00

27 lines
832 B
TypeScript

import { handleError } from "../../src/utils";
import { PostgrestError } from "@supabase/supabase-js";
import { HttpError } from "@refinedev/core";
describe("handleError", () => {
it("should transform PostgrestError into HttpError and reject the promise", async () => {
const postgrestError: PostgrestError = {
message: "Test error message",
code: "404",
details: "Not found",
hint: "Check your endpoint",
};
const expectedHttpError: HttpError = {
...postgrestError,
message: postgrestError.message,
statusCode: parseInt(postgrestError.code),
};
try {
await handleError(postgrestError);
} catch (error) {
expect(error).toEqual(expectedHttpError);
}
});
});