@@ -16,7 +16,21 @@ class CircularError extends Error {
16
16
}
17
17
}
18
18
19
- describe ( "Formatting Error Logging" , ( ) => {
19
+ class ExtendedError extends Error {
20
+ code ?: number ;
21
+ customProperty ?: string ;
22
+
23
+ constructor ( message ?: string ) {
24
+ super ( message ) ;
25
+
26
+ this . name = "ExtendedError" ;
27
+ this . stack = "ExtendedErrorStack" ;
28
+ this . code = 100 ;
29
+ this . customProperty = "ExtendedErrorCustomProperty" ;
30
+ }
31
+ }
32
+
33
+ describe ( "Formatting CircularError Logging" , ( ) => {
20
34
it ( "should fall back to a minimal error format when an exception occurs" , ( ) => {
21
35
const error = new CircularError ( "custom message" ) ;
22
36
error . backlink = error ;
@@ -29,6 +43,22 @@ describe("Formatting Error Logging", () => {
29
43
} ) ;
30
44
} ) ;
31
45
46
+ describe ( "Formatting Error Logging" , ( ) => {
47
+ it ( "should fall back to an extended error format when an exception occurs" , ( ) => {
48
+ const error = new ExtendedError ( "custom message" ) ;
49
+
50
+ const loggedError = JSON . parse ( Errors . toFormatted ( error ) . trim ( ) ) ;
51
+ loggedError . should . have . property ( "errorType" , "ExtendedError" ) ;
52
+ loggedError . should . have . property ( "errorMessage" , "custom message" ) ;
53
+ loggedError . should . have . property ( "stack" , [ "ExtendedErrorStack" ] ) ;
54
+ loggedError . should . have . property ( "code" , 100 ) ;
55
+ loggedError . should . have . property (
56
+ "customProperty" ,
57
+ "ExtendedErrorCustomProperty"
58
+ ) ;
59
+ } ) ;
60
+ } ) ;
61
+
32
62
describe ( "Converting an Error to a Runtime response" , ( ) => {
33
63
it ( "should create a RuntimeErrorResponse object when an Error object is given" , ( ) => {
34
64
const error = new Error ( "custom message" ) ;
0 commit comments