@openshift-console/dynamic-plugin-sdk
Version:
Provides core APIs, types and utilities used by dynamic plugins at runtime.
69 lines (68 loc) • 2.08 kB
JavaScript
import { CustomError } from './custom-error';
/**
* Http error
*
* Usage: throw HttpError.fromCode(404)
*/
export class HttpError extends CustomError {
constructor(message, code, response, json) {
super(message);
this.code = code;
this.response = response;
this.json = json;
}
static fromCode(code) {
return new HttpError(HttpError.messages[code], code);
}
}
HttpError.messages = {
400: 'Bad Request',
401: 'Unauthorized',
402: 'Payment Required',
403: 'Forbidden',
404: 'Not Found',
405: 'Method Not Allowed',
406: 'Not Acceptable',
407: 'Proxy Authentication Required', // RFC 7235
408: 'Request Timeout',
409: 'Conflict',
410: 'Gone',
411: 'Length Required',
412: 'Precondition Failed', // RFC 7232
413: 'Payload Too Large', // RFC 7231
414: 'URI Too Long', // RFC 7231
415: 'Unsupported Media Type',
416: 'Range Not Satisfiable', // RFC 7233
417: 'Expectation Failed',
418: "I'm a teapot", // RFC 2324
421: 'Misdirected Request', // RFC 7540
426: 'Upgrade Required',
428: 'Precondition Required', // RFC 6585
429: 'Too Many Requests', // RFC 6585
431: 'Request Header Fields Too Large', // RFC 6585
451: 'Unavailable For Legal Reasons', // RFC 7725
500: 'Internal Server Error',
501: 'Not Implemented',
502: 'Bad Gateway',
503: 'Service Unavailable',
504: 'Gateway Timeout',
505: 'HTTP Version Not Supported',
506: 'Variant Also Negotiates', // RFC 2295
510: 'Not Extended', // RFC 2774
511: 'Network Authentication Required', // RFC 6585
};
export class TimeoutError extends CustomError {
constructor(url, ms) {
super(`Call to ${url} timed out after ${ms}ms.`);
this.url = url;
this.ms = ms;
}
}
export class IncompleteDataError extends CustomError {
constructor(labels) {
super(`Could not fetch all data. This data are missing: ${labels.join(', ')}.`);
this.labels = labels;
}
}
export class RetryError extends CustomError {
}