Skip to content

Commit c8f4d62

Browse files
committed
Render /authorize errors as JSON
1 parent 7fb8e4a commit c8f4d62

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/server/auth/handlers/authorize.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,18 @@ export function authorizationHandler({ provider, rateLimit: rateLimitConfig }: A
8989
}
9090
} catch (error) {
9191
// Pre-redirect errors - return direct response
92+
//
93+
// These don't need to be JSON encoded, as they'll be displayed in a user
94+
// agent, but OTOH they all represent exceptional situations (arguably,
95+
// "programmer error"), so presenting a nice HTML page doesn't help the
96+
// user anyway.
9297
if (error instanceof OAuthError) {
9398
const status = error instanceof ServerError ? 500 : 400;
94-
res.status(status).end(error.message);
99+
res.status(status).json(error.toResponseObject());
95100
} else {
96101
console.error("Unexpected error looking up client:", error);
97-
res.status(500).end("Internal Server Error");
102+
const serverError = new ServerError("Internal Server Error");
103+
res.status(500).json(serverError.toResponseObject());
98104
}
99105

100106
return;

0 commit comments

Comments
 (0)