feat: resolve attachment user through cfw-auth binding
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
33
src/problem.ts
Normal file
33
src/problem.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
export class HttpProblem extends Error {
|
||||
constructor(
|
||||
readonly status: number,
|
||||
readonly code: string,
|
||||
message: string,
|
||||
readonly detail: Record<string, unknown> = {},
|
||||
) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
export function problemResponse(error: unknown): Response {
|
||||
const problem =
|
||||
error instanceof HttpProblem
|
||||
? error
|
||||
: new HttpProblem(500, "internal-error", "Internal server error");
|
||||
|
||||
return Response.json(
|
||||
{
|
||||
type: `https://cfw-attachment.bowong.cc/problems/${problem.code}`,
|
||||
title: problem.message,
|
||||
status: problem.status,
|
||||
detail: problem.detail,
|
||||
code: problem.code,
|
||||
},
|
||||
{
|
||||
status: problem.status,
|
||||
headers: {
|
||||
"content-type": "application/problem+json",
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user