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 {
138138 return new URL ( gitpodHost ) . toString ( ) . replace ( / \/ $ / , '' ) ;
139139}
140140
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+
141150export class WrapError extends Error {
142151 constructor (
143152 msg : string ,
144153 readonly cause : any ,
145154 readonly code ?: string
146155 ) {
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 ) {
150172 this . name = cause . name ;
151173 this . stack = this . stack + '\n\n' + cause . stack ;
152174 }
153- this . code ??= cause . code ;
175+
176+ this . code ??= cause ?. code ;
154177 }
155178}
156179
You can’t perform that action at this time.
0 commit comments