MCPcopy Create free account
hub / github.com/0010aor/FlashNotes / catchErrorCodes

Function catchErrorCodes

frontend/src/client/core/request.ts:245–312  ·  view source on GitHub ↗
(options: ApiRequestOptions, result: ApiResult)

Source from the content-addressed store, hash-verified

243}
244
245export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => {
246 const errors: Record<number, string> = {
247 400: 'Bad Request',
248 401: 'Unauthorized',
249 402: 'Payment Required',
250 403: 'Forbidden',
251 404: 'Not Found',
252 405: 'Method Not Allowed',
253 406: 'Not Acceptable',
254 407: 'Proxy Authentication Required',
255 408: 'Request Timeout',
256 409: 'Conflict',
257 410: 'Gone',
258 411: 'Length Required',
259 412: 'Precondition Failed',
260 413: 'Payload Too Large',
261 414: 'URI Too Long',
262 415: 'Unsupported Media Type',
263 416: 'Range Not Satisfiable',
264 417: 'Expectation Failed',
265 418: 'Im a teapot',
266 421: 'Misdirected Request',
267 422: 'Unprocessable Content',
268 423: 'Locked',
269 424: 'Failed Dependency',
270 425: 'Too Early',
271 426: 'Upgrade Required',
272 428: 'Precondition Required',
273 429: 'Too Many Requests',
274 431: 'Request Header Fields Too Large',
275 451: 'Unavailable For Legal Reasons',
276 500: 'Internal Server Error',
277 501: 'Not Implemented',
278 502: 'Bad Gateway',
279 503: 'Service Unavailable',
280 504: 'Gateway Timeout',
281 505: 'HTTP Version Not Supported',
282 506: 'Variant Also Negotiates',
283 507: 'Insufficient Storage',
284 508: 'Loop Detected',
285 510: 'Not Extended',
286 511: 'Network Authentication Required',
287 ...options.errors,
288 }
289
290 const error = errors[result.status]
291 if (error) {
292 throw new ApiError(options, result, error)
293 }
294
295 if (!result.ok) {
296 const errorStatus = result.status ?? 'unknown'
297 const errorStatusText = result.statusText ?? 'unknown'
298 const errorBody = (() => {
299 try {
300 return JSON.stringify(result.body, null, 2)
301 } catch (e) {
302 return undefined

Callers 1

requestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected