traveltime-api
Version:
TravelTime API SDK for node js with TypeScript
27 lines (26 loc) • 1.03 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.TravelTimeError = void 0;
class TravelTimeError extends Error {
constructor({ http_status, error_code, description, documentation_link, additional_info, }) {
super(description);
this.name = 'TravelTimeError';
this.http_status = http_status;
this.error_code = error_code;
this.description = description;
this.documentation_link = documentation_link;
this.additional_info = additional_info;
}
static isTravelTimeError(payload) {
return !!payload && (!!payload.error_code && !!payload.description);
}
static makeError(error) {
var _a;
const errorData = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data;
if (this.isTravelTimeError(errorData)) {
return new TravelTimeError(errorData);
}
return error;
}
}
exports.TravelTimeError = TravelTimeError;
;