feat(api): standardize errors as problem details
This commit is contained in:
@@ -45,3 +45,32 @@ export const velocityAccessResponseSchema = z.discriminatedUnion("allowed", [
|
||||
]);
|
||||
|
||||
export type VelocityAccessResponse = z.infer<typeof velocityAccessResponseSchema>;
|
||||
|
||||
export const problemDetailsSchema = z.object({
|
||||
type: z.string().min(1),
|
||||
title: z.string().min(1),
|
||||
status: z.number().int().min(100).max(599),
|
||||
detail: z.string().min(1).optional(),
|
||||
instance: z.string().min(1).optional(),
|
||||
extensions: z.record(z.string(), z.unknown()).optional(),
|
||||
});
|
||||
|
||||
export type ProblemDetails = z.infer<typeof problemDetailsSchema>;
|
||||
|
||||
export function problemDetails(
|
||||
type: string,
|
||||
title: string,
|
||||
status: number,
|
||||
detail?: string,
|
||||
instance?: string,
|
||||
extensions?: Record<string, unknown>,
|
||||
): ProblemDetails {
|
||||
return {
|
||||
type,
|
||||
title,
|
||||
status,
|
||||
...(detail ? { detail } : {}),
|
||||
...(instance ? { instance } : {}),
|
||||
...(extensions ? { extensions } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user