File tree Expand file tree Collapse file tree 1 file changed +27
-4
lines changed Expand file tree Collapse file tree 1 file changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -138,19 +138,42 @@ export function getServiceURL(gitpodHost: string): string {
138
138
return new URL ( gitpodHost ) . toString ( ) . replace ( / \/ $ / , '' ) ;
139
139
}
140
140
141
+ export default function isPlainObject ( value : any ) {
142
+ if ( typeof value !== 'object' || value === null ) {
143
+ return false ;
144
+ }
145
+
146
+ const prototype = Object . getPrototypeOf ( value ) ;
147
+ return ( prototype === null || prototype === Object . prototype || Object . getPrototypeOf ( prototype ) === null ) ;
148
+ }
149
+
141
150
export class WrapError extends Error {
142
151
constructor (
143
152
msg : string ,
144
153
readonly cause : any ,
145
154
readonly code ?: string
146
155
) {
147
- const isErr = cause instanceof Error ;
148
- super ( isErr ? `${ msg } : ${ cause . message } ` : `${ msg } : ${ cause } ` ) ;
149
- if ( isErr ) {
156
+ super ( ) ;
157
+
158
+ let originalMessage = cause ?. message ;
159
+ if ( ! originalMessage ) {
160
+ if ( isPlainObject ( cause ) ) {
161
+ try {
162
+ originalMessage = JSON . stringify ( cause ) ;
163
+ } catch {
164
+ }
165
+ } else {
166
+ originalMessage = cause ?. toString ( ) ;
167
+ }
168
+ }
169
+ this . message = `${ msg } : ${ originalMessage } ` ;
170
+
171
+ if ( cause instanceof Error ) {
150
172
this . name = cause . name ;
151
173
this . stack = this . stack + '\n\n' + cause . stack ;
152
174
}
153
- this . code ??= cause . code ;
175
+
176
+ this . code ??= cause ?. code ;
154
177
}
155
178
}
156
179
You can’t perform that action at this time.
0 commit comments