UNPKG

@rdfc/http-utils-processor-ts

Version:
60 lines (59 loc) 3.21 kB
var HttpUtilsErrorType; (function (HttpUtilsErrorType) { HttpUtilsErrorType[HttpUtilsErrorType["StatusCodeNotAccepted"] = 0] = "StatusCodeNotAccepted"; HttpUtilsErrorType[HttpUtilsErrorType["NoBodyInResponse"] = 1] = "NoBodyInResponse"; HttpUtilsErrorType[HttpUtilsErrorType["InvalidStatusCodeRange"] = 2] = "InvalidStatusCodeRange"; HttpUtilsErrorType[HttpUtilsErrorType["InvalidHeaders"] = 3] = "InvalidHeaders"; HttpUtilsErrorType[HttpUtilsErrorType["GenericFetchError"] = 4] = "GenericFetchError"; HttpUtilsErrorType[HttpUtilsErrorType["IllegalParameters"] = 5] = "IllegalParameters"; HttpUtilsErrorType[HttpUtilsErrorType["ConnectionError"] = 6] = "ConnectionError"; HttpUtilsErrorType[HttpUtilsErrorType["TimeOutError"] = 7] = "TimeOutError"; HttpUtilsErrorType[HttpUtilsErrorType["UnauthorizedError"] = 8] = "UnauthorizedError"; HttpUtilsErrorType[HttpUtilsErrorType["CredentialIssue"] = 9] = "CredentialIssue"; HttpUtilsErrorType[HttpUtilsErrorType["OAuth2TokenError"] = 10] = "OAuth2TokenError"; HttpUtilsErrorType[HttpUtilsErrorType["InvalidCronExpression"] = 11] = "InvalidCronExpression"; })(HttpUtilsErrorType || (HttpUtilsErrorType = {})); export class HttpUtilsError extends Error { type; constructor(message, type) { super(message); this.name = "HttpUtilsError"; this.type = type; } static statusCodeNotAccepted(statusCode) { return new HttpUtilsError(`Status code ${statusCode} not accepted`, HttpUtilsErrorType.StatusCodeNotAccepted); } static noBodyInResponse() { return new HttpUtilsError("No body in response", HttpUtilsErrorType.NoBodyInResponse); } static invalidStatusCodeRange() { return new HttpUtilsError("Invalid status code range", HttpUtilsErrorType.InvalidStatusCodeRange); } static invalidHeaders() { return new HttpUtilsError("Invalid headers", HttpUtilsErrorType.InvalidHeaders); } static genericFetchError(error) { return new HttpUtilsError(`Generic fetch error: ${error.message}`, HttpUtilsErrorType.GenericFetchError); } static illegalParameters(info = null) { return new HttpUtilsError(info ?? "Illegal parameters", HttpUtilsErrorType.IllegalParameters); } static connectionError() { return new HttpUtilsError("Connection error", HttpUtilsErrorType.ConnectionError); } static timeOutError(ms) { return new HttpUtilsError(`Request exceeded time limit of ${ms} ms`, HttpUtilsErrorType.TimeOutError); } static unauthorizedError() { return new HttpUtilsError("Unauthorized", HttpUtilsErrorType.UnauthorizedError); } static credentialIssue() { return new HttpUtilsError("Credentials are invalid or have insufficient access", HttpUtilsErrorType.CredentialIssue); } static oAuth2TokenError(code) { return new HttpUtilsError(`An issue occurred while retrieving the OAuth2 token. Response with status code ${code}.`, HttpUtilsErrorType.OAuth2TokenError); } static invalidCronExpression() { return new HttpUtilsError("The provided cron job expression is invalid", HttpUtilsErrorType.InvalidCronExpression); } }