2025-09-14 18:12:29 +00:00
|
|
|
import { ConvexError } from "convex/values"
|
|
|
|
|
|
|
|
export enum Code {
|
2025-09-21 22:24:24 +00:00
|
|
|
Conflict = "Conflict",
|
2025-09-14 18:12:29 +00:00
|
|
|
DirectoryExists = "DirectoryExists",
|
2025-09-16 22:36:26 +00:00
|
|
|
DirectoryNotFound = "DirectoryNotFound",
|
2025-09-14 18:12:29 +00:00
|
|
|
FileExists = "FileExists",
|
|
|
|
Internal = "Internal",
|
2025-09-15 21:44:41 +00:00
|
|
|
Unauthenticated = "Unauthenticated",
|
2025-09-14 18:12:29 +00:00
|
|
|
}
|
|
|
|
|
2025-09-21 22:24:24 +00:00
|
|
|
export type ApplicationError = ConvexError<{ code: Code; message?: string }>
|
2025-09-14 18:12:29 +00:00
|
|
|
|
|
|
|
export function isApplicationError(error: unknown): error is ApplicationError {
|
2025-09-15 22:58:23 +00:00
|
|
|
return error instanceof ConvexError && "code" in error.data
|
2025-09-14 18:12:29 +00:00
|
|
|
}
|
|
|
|
|
2025-09-21 22:24:24 +00:00
|
|
|
export function create(code: Code, message?: string): ApplicationError {
|
2025-09-14 18:12:29 +00:00
|
|
|
return new ConvexError({
|
|
|
|
code,
|
2025-09-21 15:12:05 +00:00
|
|
|
message:
|
|
|
|
code === Code.Internal ? "Internal application error" : message,
|
2025-09-14 18:12:29 +00:00
|
|
|
})
|
|
|
|
}
|