( response: Response, )
| 155 | * experimental-until-21 which is incorrect. Pattern matches existing |
| 156 | * createAuthFetch suppressions in this file. */ |
| 157 | export 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 | /** |
no test coverage detected