export class ApiError extends Error { constructor ( readonly message , public readonly code , public readonly httpStatus = 400 , public readonly defaultParams ? ) { super ( message ) ; } withDefaultParams ( ) { if ( this . defaultParams ) return new ApiError ( applyParamsToString ( this . message , this . defaultParams ) , this . code , this . httpStatus ) ; return this ; } withParams ( ... params ) { return new ApiError ( applyParamsToString ( this . message , params ) , this . code , this . httpStatus ) ; } } export function applyParamsToString ( s , params ) { let newString = s ; params . forEach ( ( a ) => { newString = newString . replace ( "{}" , "" + a ) ; } ) ; return newString ; }