import { GraphQLError } from 'graphql' ; export class FinchError extends Error implements GraphQLError { public extensions : Record < string , any > ; readonly name : GraphQLError [ 'name' ] ; readonly locations : GraphQLError [ 'locations' ] ; readonly path : GraphQLError [ 'path' ] ; readonly source : GraphQLError [ 'source' ] ; readonly positions : GraphQLError [ 'positions' ] ; readonly nodes : GraphQLError [ 'nodes' ] ; public originalError : GraphQLError [ 'originalError' ] ; [ key ] : any ; constructor ( message , code ? , extensions ? ) { super ( message ) ; this . name = this . name ?? '' ; if ( extensions ) { Object . keys ( extensions ) . filter ( keyName => keyName !== 'message' && keyName !== 'extensions' ) . forEach ( key => { this [ key ] = extensions [ key ] ; } ) ; } if ( ! this . name ) { Object . defineProperty ( this , 'name' , { value : 'FinchError' } ) ; } const userProvidedExtensions = ( extensions && extensions . extensions ) || null ; this . extensions = { ... extensions , ... userProvidedExtensions , code } ; } } export function toFinchError ( error , code = 'INTERNAL_SERVER_ERROR' ) { const err = error ; if ( err . extensions ) { err . extensions . code = code ; } else { err . extensions = { code } ; } return err as Error & { extensions : Record < string , any > ; } ; }