@@ -16,7 +16,21 @@ class CircularError extends Error {
1616 }
1717}
1818
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" , ( ) => {
2034 it ( "should fall back to a minimal error format when an exception occurs" , ( ) => {
2135 const error = new CircularError ( "custom message" ) ;
2236 error . backlink = error ;
@@ -29,6 +43,22 @@ describe("Formatting Error Logging", () => {
2943 } ) ;
3044} ) ;
3145
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+
3262describe ( "Converting an Error to a Runtime response" , ( ) => {
3363 it ( "should create a RuntimeErrorResponse object when an Error object is given" , ( ) => {
3464 const error = new Error ( "custom message" ) ;
0 commit comments