Something went wrong. Try again.
A social knowledge tool for research trails, built on ATProto semble.so
research-tool social-network tools-for-thought atproto
Something went wrong. Try again.
1.4 kB · 52 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253// API error types for frontend client
export interface ApiErrorResponse { message: string; code?: string; details?: any;}
export class ApiError extends Error { constructor( message: string, public statusCode: number, public code?: string, public details?: any, ) { super(message); this.name = 'ApiError'; }}
/** * Thrown by client DAL functions when there is no verified session. Extends * ApiError with a 401 so the global auth error handler (providers/tanstack.tsx) * treats it like any backend 401 and logs the user out, instead of the retry * path a plain Error would take. */export class NoSessionError extends ApiError { constructor() { super('No session found', 401, 'NO_SESSION'); this.name = 'NoSessionError'; }}
/** * Returns true when the error is a 401 ApiError — an authoritative "not * authenticated". Retrying these is never useful. */export function isUnauthorizedApiError(err: unknown): boolean { return err instanceof ApiError && err.statusCode === 401;}
/** * Returns true when the error is a 404 ApiError, optionally matching a specific * error `code` (e.g. 'PROFILE_NOT_FOUND', 'COLLECTION_NOT_FOUND'). */export function isNotFoundApiError(err: unknown, code?: string): boolean { return ( err instanceof ApiError && err.statusCode === 404 && (!code || err.code === code) );}