errorMapping.test.js 993 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* @vitest-environment node */
  2. import { describe, it, expect } from "vitest";
  3. import { ApiClientError } from "@/lib/frontend/apiClient";
  4. import { mapExplorerError } from "./errorMapping";
  5. describe("lib/frontend/explorer/errorMapping", () => {
  6. it("maps unauthenticated", () => {
  7. const err = new ApiClientError({
  8. status: 401,
  9. code: "AUTH_UNAUTHENTICATED",
  10. message: "Unauthorized",
  11. });
  12. expect(mapExplorerError(err)?.kind).toBe("unauthenticated");
  13. });
  14. it("maps forbidden", () => {
  15. const err = new ApiClientError({
  16. status: 403,
  17. code: "AUTH_FORBIDDEN_BRANCH",
  18. message: "Forbidden",
  19. });
  20. expect(mapExplorerError(err)?.kind).toBe("forbidden");
  21. });
  22. it("maps not found", () => {
  23. const err = new ApiClientError({
  24. status: 404,
  25. code: "FS_NOT_FOUND",
  26. message: "Not found",
  27. });
  28. expect(mapExplorerError(err)?.kind).toBe("notfound");
  29. });
  30. it("maps unknown to generic", () => {
  31. expect(mapExplorerError(new Error("boom"))?.kind).toBe("generic");
  32. });
  33. });