UNPKG

@foundry-ai/api-errors

Version:

Common errors that can be thrown and caught reliably across services

20 lines (19 loc) 752 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const baseError_1 = require("./baseError"); function _head(array) { return (array && array.length) ? array[0] : undefined; } class BadRequestError extends baseError_1.BaseError { static createFromValidationError(validationError) { const primaryError = _head(validationError.errors); const errorMessage = _head(primaryError.messages); return new BadRequestError(errorMessage); } constructor(message = 'Bad Request', status = 400) { super(message, status, 'bad_request_error'); Error.captureStackTrace(this, this.constructor); this.name = this.constructor.name; } } exports.BadRequestError = BadRequestError;