( status: number, statusText: string, errorText: string )
| 75 | * Used by API routes that have a Response object rather than parsed data. |
| 76 | */ |
| 77 | export function parseGraphErrorMessage( |
| 78 | status: number, |
| 79 | statusText: string, |
| 80 | errorText: string |
| 81 | ): string { |
| 82 | try { |
| 83 | const data = JSON.parse(errorText) |
| 84 | const message = parseGraphErrorFromData(data) |
| 85 | if (message) { |
| 86 | // If the only thing we found was the bare error code, append status for context. |
| 87 | const root = data?.error |
| 88 | if ( |
| 89 | root && |
| 90 | message === root.code?.trim?.() && |
| 91 | !(typeof root.message === 'string' && root.message.trim()) |
| 92 | ) { |
| 93 | return `${message} (${status} ${statusText})` |
| 94 | } |
| 95 | return message |
| 96 | } |
| 97 | } catch { |
| 98 | if (errorText?.trim()) return errorText.trim() |
| 99 | } |
| 100 | |
| 101 | return statusText ? `${status} ${statusText}` : `Microsoft Graph request failed (${status})` |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Read an error response body and produce a developer-readable message. |
no test coverage detected