|
| 1 | +// Copied from ember-fetch addon/utils/errors.ts (converted to JavaScript) |
| 2 | +// This file contains utility functions to check the type of HTTP response errors. |
| 3 | + |
| 4 | +/** |
| 5 | + * Checks if the given response represents an unauthorized request error |
| 6 | + */ |
| 7 | +export function isUnauthorizedResponse(response) { |
| 8 | + return response.status === 401; |
| 9 | +} |
| 10 | + |
| 11 | +/** |
| 12 | + * Checks if the given response represents a forbidden request error |
| 13 | + */ |
| 14 | +export function isForbiddenResponse(response) { |
| 15 | + return response.status === 403; |
| 16 | +} |
| 17 | + |
| 18 | +/** |
| 19 | + * Checks if the given response represents an invalid request error |
| 20 | + */ |
| 21 | +export function isInvalidResponse(response) { |
| 22 | + return response.status === 422; |
| 23 | +} |
| 24 | + |
| 25 | +/** |
| 26 | + * Checks if the given response represents a bad request error |
| 27 | + */ |
| 28 | +export function isBadRequestResponse(response) { |
| 29 | + return response.status === 400; |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Checks if the given response represents a "not found" error |
| 34 | + */ |
| 35 | +export function isNotFoundResponse(response) { |
| 36 | + return response.status === 404; |
| 37 | +} |
| 38 | + |
| 39 | +/** |
| 40 | + * Checks if the given response represents a "gone" error |
| 41 | + */ |
| 42 | +export function isGoneResponse(response) { |
| 43 | + return response.status === 410; |
| 44 | +} |
| 45 | + |
| 46 | +/** |
| 47 | + * Checks if the given error is an "abort" error |
| 48 | + */ |
| 49 | +export function isAbortError(error) { |
| 50 | + return error.name === "AbortError"; |
| 51 | +} |
| 52 | + |
| 53 | +/** |
| 54 | + * Checks if the given response represents a conflict error |
| 55 | + */ |
| 56 | +export function isConflictResponse(response) { |
| 57 | + return response.status === 409; |
| 58 | +} |
| 59 | + |
| 60 | +/** |
| 61 | + * Checks if the given response represents a server error |
| 62 | + */ |
| 63 | +export function isServerErrorResponse(response) { |
| 64 | + return response.status >= 500 && response.status < 600; |
| 65 | +} |
0 commit comments