mirror of
https://github.com/get-drexa/drive.git
synced 2025-12-01 14:01:40 +00:00
- Update error() helper to throw ConvexError instead of plain objects - Add isApplicationConvexError() type guard for client-side error checking - Fix Vite config to include convex/values in optimizeDeps for proper instanceof checks - Update error handling to check ConvexError wrapper and extract data property This ensures all application errors are properly typed and can be identified using instanceof ConvexError on the client side. Co-authored-by: Ona <no-reply@ona.com>
45 lines
963 B
TypeScript
45 lines
963 B
TypeScript
import { ConvexError } from "convex/values"
|
|
|
|
export enum ErrorCode {
|
|
Conflict = "Conflict",
|
|
DirectoryExists = "DirectoryExists",
|
|
FileExists = "FileExists",
|
|
Internal = "Internal",
|
|
Unauthenticated = "Unauthenticated",
|
|
NotFound = "NotFound",
|
|
StorageQuotaExceeded = "StorageQuotaExceeded",
|
|
}
|
|
|
|
export type ApplicationErrorData = { code: ErrorCode; message?: string }
|
|
|
|
export function isApplicationError(
|
|
error: unknown,
|
|
): error is ApplicationErrorData {
|
|
return (
|
|
error !== null &&
|
|
typeof error === "object" &&
|
|
"code" in error &&
|
|
"message" in error &&
|
|
Object.values(ErrorCode).includes(
|
|
(error as { code: string }).code as ErrorCode,
|
|
)
|
|
)
|
|
}
|
|
|
|
export function createErrorData(
|
|
code: ErrorCode,
|
|
message?: string,
|
|
): ApplicationErrorData {
|
|
return {
|
|
code,
|
|
message:
|
|
code === ErrorCode.Internal
|
|
? "Internal application error"
|
|
: message,
|
|
}
|
|
}
|
|
|
|
export function error(data: ApplicationErrorData): never {
|
|
throw new ConvexError(data)
|
|
}
|