@@ -213,6 +213,44 @@ describe('Logger', function() {
213
213
expect ( logArguments . error_message ) . to . eql ( error . message ) ;
214
214
expect ( logArguments . error_data . length ) . to . eql ( 3004 ) ;
215
215
} ) ;
216
+
217
+ describe ( 'when not an Error instance is passed as error' , function ( ) {
218
+ [
219
+ { type : 'custom object' , value : { } } ,
220
+ { type : 'string' , value : 'error' } ,
221
+ { type : 'null' , value : null } ,
222
+ { type : 'number' , value : 12 } ,
223
+ { type : 'bool' , value : true }
224
+ ] . forEach ( ( { type, value } ) => {
225
+ it ( `should not throw error when ${ type } is passed as error` , function ( ) {
226
+ expect ( ( ) => logger . customError ( 'error' , 'hi' , value , { details : 'here' } ) ) . to . not . throw ( ) ;
227
+ } ) ;
228
+ } ) ;
229
+
230
+ it ( 'should log error properties from custom error object' , function ( ) {
231
+ const errorObject = { name : 'Error' , message : 'My custom error' , stack : 'Stack' , data : { value : 1 } } ;
232
+
233
+ logger . customError ( 'error' , 'hi' , errorObject , { details : 'here' } ) ;
234
+
235
+ const logArguments = JSON . parse ( Logger . config . output . args [ 0 ] ) ;
236
+
237
+ expect ( logArguments . error_name ) . to . eql ( errorObject . name ) ;
238
+ expect ( logArguments . error_stack ) . to . eql ( errorObject . stack ) ;
239
+ expect ( logArguments . error_message ) . to . eql ( errorObject . message ) ;
240
+ expect ( logArguments . error_data ) . to . eql ( JSON . stringify ( errorObject . data ) ) ;
241
+ } ) ;
242
+
243
+ it ( 'should not log additional or missing error properties from custom error object' , function ( ) {
244
+ const errorObject = { color : 'color' , value : 'value' } ;
245
+
246
+ logger . customError ( 'error' , 'hi' , errorObject , { details : 'here' } ) ;
247
+
248
+ const logArguments = JSON . parse ( Logger . config . output . args [ 0 ] ) ;
249
+
250
+ expect ( logArguments ) . to . not . have . any . keys ( 'error_name' , 'error_stack' , 'error_message' , 'error_data' ) ;
251
+ expect ( logArguments ) . to . not . have . any . keys ( 'color' , 'value' ) ;
252
+ } ) ;
253
+ } ) ;
216
254
} ) ;
217
255
218
256
describe ( '#configure' , function ( ) {
0 commit comments