import * as Boom from '@hapi/boom' ; import HttpStatus from '@xpring-eng/http-status' ; import { Response } from 'express' ; import logger from '../logger' ; param errorCode param msg param res param err export default function handleHttpError ( errorCode , msg , res , err ? ) { if ( errorCode >= HttpStatus . InternalServerError ) { logger . error ( errorCode , ':' , err ?. toString ( ) ?? msg ) ; } else { logger . warn ( errorCode , ':' , err ?. toString ( ) ?? msg ) ; } let error ; switch ( errorCode ) { case HttpStatus . BadRequest : error = Boom . badRequest ( msg ) . output . payload ; break ; case HttpStatus . NotFound : error = Boom . notFound ( msg ) . output . payload ; break ; case HttpStatus . Conflict : error = Boom . conflict ( msg ) . output . payload ; break ; case HttpStatus . UnsupportedMediaType : error = Boom . unsupportedMediaType ( msg ) . output . payload ; break ; default : error = Boom . badImplementation ( msg ) . output . payload ; } res . status ( errorCode ) . json ( error ) ; }