import { APIBaseError , BadRequestError , ErrorUtils as BaseErrorUtils , isAPIError } from '@0x/api-utils' ; import * as HttpStatus from 'http-status-codes' ; import { APIErrorCodes , apiErrorCodesToReasons } from '../errors' ; class ErrorUtils extends BaseErrorUtils { public generateError ( err ) { if ( isAPIError ( err ) && isAPIBadRequestError ( err ) && Object . values ( APIErrorCodes ) . includes ( err . generalErrorCode ) ) { const statusCode = err . statusCode ; const code = err . generalErrorCode ; return { statusCode , errorBody : { code , reason : apiErrorCodesToReasons [ code ] , } , } ; } return super . generateError ( err ) ; } } function isAPIBadRequestError ( error ) { return error . statusCode === HttpStatus . BAD_REQUEST ; } export const errorUtils = new ErrorUtils ( ) ; export const errorHandler = errorUtils . getErrorHandler ( ) ;