( status: number, response?: ProfileRequestResponse, )
| 261 | const profileNotFoundErrorCodes = new Set(['FORBIDDEN', 'NOT_FOUND']); |
| 262 | |
| 263 | export const classifyProfileRequest = ( |
| 264 | status: number, |
| 265 | response?: ProfileRequestResponse, |
| 266 | ): ProfileRequestResult => { |
| 267 | if (status === 404) { |
| 268 | return { status: 'notFound' }; |
| 269 | } |
| 270 | |
| 271 | if (status >= 400) { |
| 272 | return { |
| 273 | status: 'failed', |
| 274 | error: new Error(`Failed to fetch profile: ${status}`), |
| 275 | }; |
| 276 | } |
| 277 | |
| 278 | if (response?.data?.user) { |
| 279 | return { status: 'found', user: response.data.user }; |
| 280 | } |
| 281 | |
| 282 | const errorCode = response?.errors?.[0]?.extensions?.code; |
| 283 | if (errorCode && profileNotFoundErrorCodes.has(errorCode)) { |
| 284 | return { status: 'notFound' }; |
| 285 | } |
| 286 | |
| 287 | return { |
| 288 | status: 'failed', |
| 289 | error: new Error('Failed to fetch profile'), |
| 290 | }; |
| 291 | }; |
| 292 | |
| 293 | const getProfileRequest = async (id: string): Promise<ProfileRequestResult> => { |
| 294 | const userRes = await fetch(graphqlUrl, { |
no outgoing calls
no test coverage detected