MCPcopy Index your code
hub / github.com/codeaashu/claude-code / normalizeOAuthErrorBody

Function normalizeOAuthErrorBody

src/services/mcp/auth.ts:157–190  ·  view source on GitHub ↗
(
  response: Response,
)

Source from the content-addressed store, hash-verified

155 * experimental-until-21 which is incorrect. Pattern matches existing
156 * createAuthFetch suppressions in this file. */
157export async function normalizeOAuthErrorBody(
158 response: Response,
159): Promise<Response> {
160 if (!response.ok) {
161 return response
162 }
163 const text = await response.text()
164 let parsed: unknown
165 try {
166 parsed = jsonParse(text)
167 } catch {
168 return new Response(text, response)
169 }
170 if (OAuthTokensSchema.safeParse(parsed).success) {
171 return new Response(text, response)
172 }
173 const result = OAuthErrorResponseSchema.safeParse(parsed)
174 if (!result.success) {
175 return new Response(text, response)
176 }
177 const normalized = NONSTANDARD_INVALID_GRANT_ALIASES.has(result.data.error)
178 ? {
179 error: 'invalid_grant',
180 error_description:
181 result.data.error_description ??
182 `Server returned non-standard error code: ${result.data.error}`,
183 }
184 : result.data
185 return new Response(jsonStringify(normalized), {
186 status: 400,
187 statusText: 'Bad Request',
188 headers: response.headers,
189 })
190}
191/* eslint-enable eslint-plugin-n/no-unsupported-features/node-builtins */
192
193/**

Callers 1

createAuthFetchFunction · 0.85

Calls 4

jsonParseFunction · 0.85
jsonStringifyFunction · 0.85
textMethod · 0.80
hasMethod · 0.45

Tested by

no test coverage detected