import * as HTTP_STATUS from 'http-status' ; import { IError , IHTTPError } from '@interfaces' ; import { TypeplateError } from '@errors' ; description export class MySQLError extends TypeplateError implements IHTTPError { description statusCode : number ; description statusText : string ; description errors : Array < string > ; constructor ( error ) { super ( 'MySQL engine was failed' ) ; const converted = this . convertError ( error . errno , error . message ) ; this . statusCode = converted . statusCode ; this . statusText = converted . statusText ; this . errors = [ converted . error ] ; } description param errno param message example example example example example example private convertError ( errno , message ) { switch ( errno ) { case 1052 : return { statusCode : 409 , statusText : HTTP_STATUS [ '409_NAME' ] , error : message } ; case 1054 : return { statusCode : 409 , statusText : HTTP_STATUS [ '409_NAME' ] , error : message } ; case 1062 : return { statusCode : 409 , statusText : HTTP_STATUS [ '409_NAME' ] , error : message } ; case 1452 : return { statusCode : 409 , statusText : HTTP_STATUS [ '409_NAME' ] , error : message } ; case 1364 : return { statusCode : 422 , statusText : HTTP_STATUS [ '422_NAME' ] , error : message } ; case 1406 : return { statusCode : 422 , statusText : HTTP_STATUS [ '422_NAME' ] , error : message } ; default : return { statusCode : 422 , statusText : HTTP_STATUS [ '422_NAME' ] , error : message } ; } } }