UNPKG

@hubs101/booking-api-skd-client

Version:
31 lines (30 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleFetchErrors = void 0; const utils_1 = require("./utils"); const codeStyle = "font-weight: bold; font-size: 18px; color: red;"; const messageStyle = " font-size: 14px; color: yellow;"; const endpointStyle = " font-size: 12px; color: blue;"; const handleFetchErrors = (data, endpointURL) => { const errorCode = `Error code : ${data.status}`; const endpoint = `Endpoint : ${endpointURL}`; if (String(data.status).startsWith("5")) { console.log(`%c ${errorCode}`, codeStyle); console.log(`%c ${endpoint}`, endpointStyle); console.log(`%c ${data.statusText}`, messageStyle); throw new Error(data.statusText); } if (data.status === 400 && data.invalid_fields) { console.log(`%c ${errorCode}`, codeStyle); console.log(`%c ${endpoint}`, endpointStyle); console.log(`%c ${(0, utils_1.createErrorMessageFromError)(data)}`, messageStyle); throw new Error((0, utils_1.createErrorMessageFromError)(data)); } if (String(data.status).startsWith("4")) { console.log(`%c ${errorCode}`, codeStyle); console.log(`%c ${endpoint}`, endpointStyle); console.log(`%c ${data.message}`, messageStyle); throw new Error(data.message); } }; exports.handleFetchErrors = handleFetchErrors;