MCPcopy Index your code
hub / github.com/modelcontextprotocol/typescript-sdk / parseErrorResponse

Function parseErrorResponse

src/client/auth.ts:379–393  ·  view source on GitHub ↗
(input: Response | string)

Source from the content-addressed store, hash-verified

377 * @returns A Promise that resolves to an OAuthError instance
378 */
379export async function parseErrorResponse(input: Response | string): Promise<OAuthError> {
380 const statusCode = input instanceof Response ? input.status : undefined;
381 const body = input instanceof Response ? await input.text() : input;
382
383 try {
384 const result = OAuthErrorResponseSchema.parse(JSON.parse(body));
385 const { error, error_description, error_uri } = result;
386 const errorClass = OAUTH_ERRORS[error] || ServerError;
387 return new errorClass(error_description || '', error_uri);
388 } catch (error) {
389 // Not a valid OAuth error response, but try to inform the user of the raw data anyway
390 const errorMessage = `${statusCode ? `HTTP ${statusCode}: ` : ''}Invalid OAuth error response: ${error}. Raw body: ${body}`;
391 return new ServerError(errorMessage);
392 }
393}
394
395/**
396 * Orchestrates the full auth flow with a server.

Callers 2

executeTokenRequestFunction · 0.85
registerClientFunction · 0.85

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…