WIP! A BB-style forum, on the ATmosphere! We're still working... we'll be back soon when we have something to show off!
node typescript hono htmx atproto
at root/atb-56-theme-caching-layer 87 lines 2.7 kB view raw
1import { describe, it, expect } from "vitest"; 2import { isProgrammingError, isNetworkError, isAuthError, isDatabaseError } from "../errors.js"; 3 4describe("isProgrammingError", () => { 5 it("returns true for TypeError", () => { 6 expect(isProgrammingError(new TypeError("x is not a function"))).toBe(true); 7 }); 8 9 it("returns true for ReferenceError", () => { 10 expect(isProgrammingError(new ReferenceError("x is not defined"))).toBe(true); 11 }); 12 13 it("returns true for SyntaxError", () => { 14 expect(isProgrammingError(new SyntaxError("unexpected token"))).toBe(true); 15 }); 16 17 it("returns false for generic Error", () => { 18 expect(isProgrammingError(new Error("something failed"))).toBe(false); 19 }); 20 21 it("returns false for non-error values", () => { 22 expect(isProgrammingError("string")).toBe(false); 23 expect(isProgrammingError(null)).toBe(false); 24 }); 25}); 26 27describe("isNetworkError", () => { 28 it("returns true for fetch failed", () => { 29 expect(isNetworkError(new Error("fetch failed"))).toBe(true); 30 }); 31 32 it("returns true for ECONNREFUSED", () => { 33 expect(isNetworkError(new Error("ECONNREFUSED"))).toBe(true); 34 }); 35 36 it("returns true for timeout", () => { 37 expect(isNetworkError(new Error("request timeout"))).toBe(true); 38 }); 39 40 it("returns true for ETIMEDOUT", () => { 41 expect(isNetworkError(new Error("ETIMEDOUT"))).toBe(true); 42 }); 43 44 it("returns false for generic Error", () => { 45 expect(isNetworkError(new Error("something else"))).toBe(false); 46 }); 47 48 it("returns false for non-Error values", () => { 49 expect(isNetworkError("string")).toBe(false); 50 }); 51}); 52 53describe("isAuthError", () => { 54 it("returns true for invalid credentials", () => { 55 expect(isAuthError(new Error("Invalid identifier or password"))).toBe(true); 56 }); 57 58 it("returns true for authentication failed", () => { 59 expect(isAuthError(new Error("Authentication failed"))).toBe(true); 60 }); 61 62 it("returns true for unauthorized", () => { 63 expect(isAuthError(new Error("Unauthorized"))).toBe(true); 64 }); 65 66 it("returns false for network errors", () => { 67 expect(isAuthError(new Error("fetch failed"))).toBe(false); 68 }); 69 70 it("returns false for non-Error values", () => { 71 expect(isAuthError("string")).toBe(false); 72 }); 73}); 74 75describe("isDatabaseError", () => { 76 it("returns true for pool errors", () => { 77 expect(isDatabaseError(new Error("pool exhausted"))).toBe(true); 78 }); 79 80 it("returns true for postgres errors", () => { 81 expect(isDatabaseError(new Error("postgres connection lost"))).toBe(true); 82 }); 83 84 it("returns false for generic errors", () => { 85 expect(isDatabaseError(new Error("something else"))).toBe(false); 86 }); 87});