import { GraphQLError , GraphQLFormattedError } from 'graphql' ; import ILogger from '../infrastructure/logger/ILogger' ; import { getErrorResponse } from './responseGenerator' ; export default ( logger ) => ( error ) : GraphQLFormattedError => { const code = error . extensions ?. exception ?. code ?? 'no-code' ; if ( code === 'INTERNAL_SERVER_ERROR' ) { logger . info ( error ) ; } else { logger . error ( error ) ; } let statusCode = 500 ; switch ( code ) { case 'ValidationError' : statusCode = 401 ; break ; case 'UNAUTHENTICATED' : statusCode = 403 ; break ; case 'BAD_USER_INPUT' : statusCode = 412 ; break ; default : statusCode = 500 ; } return getErrorResponse ( error . message , code , statusCode ) ; } ;