File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,6 +36,15 @@ compatible with `Error` and introduces a few new features:
3636- Use ` details ` , ` domain ` and ` tag ` to customize the error object and help easily distinguish between different
3737 errors
3838
39+ ## Override default log method (default is ` console.log ` )
40+
41+ To override the default log method, set the static property ` LOG_METHOD ` to a function that accepts any number of
42+ arguments and returns nothing. The default log method is ` console.log ` .
43+
44+ ## Override default generic error code and message
45+
46+ To override the default generic error code and message, set the static properties ` GENERIC_CODE ` and ` GENERIC_MESSAGE ` .
47+
3948## new ErrorObjectFromPayload(payload, options)
4049
4150To parse errors from any payload, check
Original file line number Diff line number Diff line change 11{
22 "name" : " @smbcheeky/error-object" ,
33 "description" : " Create errors that can be both thrown and returned. Make error handling easier for both JavaScript and TypeScript." ,
4- "version" : " 1.1.9 " ,
4+ "version" : " 1.2.0 " ,
55 "main" : " dist/index.js" ,
66 "module" : " dist/index.mjs" ,
77 "types" : " dist/index.d.ts" ,
Original file line number Diff line number Diff line change @@ -117,8 +117,35 @@ const runFieldChecks = () => {
117117 // }
118118} ;
119119
120+ const runOverrides = ( ) => {
121+ console . log (
122+ "\n-Overrides------------------------------------------------------------------------------\n" ,
123+ ) ;
124+
125+ ErrorObject . GENERIC_CODE = "specific?" ;
126+ ErrorObject . GENERIC_MESSAGE = "Something went :(" ;
127+
128+ let objectWithLogic = { complex : true } ;
129+
130+ ErrorObject . LOG_METHOD = ( ) => {
131+ objectWithLogic . complex = false ;
132+ } ;
133+
134+ console . log ( objectWithLogic , "should be { complex: true }" ) ;
135+ ErrorObject . generic ( ) . log ( "LOG" ) ;
136+ console . log ( objectWithLogic , "should be { complex: false }" ) ;
137+
138+ // { complex: true } should be { complex: true }
139+ // { complex: false } should be { complex: false }
140+
141+ ErrorObject . LOG_METHOD = null as any ;
142+ ErrorObject . generic ( ) . log ( "LOG" ) . debugLog ( "LOG" ) . verboseLog ( "LOG" ) ;
143+ // should not show anything
144+ } ;
145+
120146console . log ( "\n\n\n\n\n\n" ) ;
121147
122148runSanityChecks ( ) ;
123149runTypeChecks ( ) ;
124150runFieldChecks ( ) ;
151+ runOverrides ( ) ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 2828 " @jridgewell/sourcemap-codec" " ^1.4.10"
2929
3030" @smbcheeky/error-object@file:.. " :
31- version "1.1.8 "
31+ version "1.1.9 "
3232 resolved "file:.."
3333
3434" @tsconfig/node10@^1.0.7 " :
You can’t perform that action at this time.
0 commit comments