@@ -30,6 +30,26 @@ function tryToUnwrapZonejsError(error: unknown): unknown | Error {
30
30
: error ;
31
31
}
32
32
33
+ function extractHttpModuleError ( error : HttpErrorResponse ) : string | Error {
34
+ // The `error` property of http exception can be either an `Error` object, which we can use directly...
35
+ if ( error . error instanceof Error ) {
36
+ return error . error ;
37
+ }
38
+
39
+ // ... or an`ErrorEvent`, which can provide us with the message but no stack...
40
+ if ( error . error instanceof ErrorEvent && error . error . message ) {
41
+ return error . error . message ;
42
+ }
43
+
44
+ // ...or the request body itself, which we can use as a message instead.
45
+ if ( typeof error . error === 'string' ) {
46
+ return `Server returned code ${ error . status } with body "${ error . error } "` ;
47
+ }
48
+
49
+ // If we don't have any detailed information, fallback to the request message itself.
50
+ return error . message ;
51
+ }
52
+
33
53
/**
34
54
* Implementation of Angular's ErrorHandler provider that can be used as a drop-in replacement for the stock one.
35
55
*/
@@ -104,23 +124,7 @@ class SentryErrorHandler implements AngularErrorHandler {
104
124
105
125
// If it's http module error, extract as much information from it as we can.
106
126
if ( error instanceof HttpErrorResponse ) {
107
- // The `error` property of http exception can be either an `Error` object, which we can use directly...
108
- if ( error . error instanceof Error ) {
109
- return error . error ;
110
- }
111
-
112
- // ... or an`ErrorEvent`, which can provide us with the message but no stack...
113
- if ( error . error instanceof ErrorEvent && error . error . message ) {
114
- return error . error . message ;
115
- }
116
-
117
- // ...or the request body itself, which we can use as a message instead.
118
- if ( typeof error . error === 'string' ) {
119
- return `Server returned code ${ error . status } with body "${ error . error } "` ;
120
- }
121
-
122
- // If we don't have any detailed information, fallback to the request message itself.
123
- return error . message ;
127
+ return extractHttpModuleError ( error ) ;
124
128
}
125
129
126
130
// Nothing was extracted, fallback to default error message.
0 commit comments