Fix some DEV errors showing up as DEV: [{}]
Summary: Collections of errors were not reported correctly in the UI. Also, reporting errors could crash flipper if the error is not serializable (for example due to being cyclic). Reviewed By: jknoxville Differential Revision: D18595257 fbshipit-source-id: 689b6dbfe5d7daa6d84bd703dba9daa6be2e6b82
This commit is contained in:
committed by
Facebook Github Bot
parent
68d752dd21
commit
f9f1d60267
@@ -13,12 +13,21 @@ export class CancelledPromiseError extends Error {
|
|||||||
this.name = 'CancelledPromiseError';
|
this.name = 'CancelledPromiseError';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export function getStringFromErrorLike(e: any) {
|
|
||||||
if (typeof e == 'string') {
|
export function getStringFromErrorLike(e: any): string {
|
||||||
|
if (Array.isArray(e)) {
|
||||||
|
return e.map(getStringFromErrorLike).join(' ');
|
||||||
|
} else if (typeof e == 'string') {
|
||||||
return e;
|
return e;
|
||||||
} else if (e instanceof Error) {
|
} else if (e instanceof Error) {
|
||||||
return e.message;
|
return e.message || e.toString();
|
||||||
} else {
|
} else {
|
||||||
return JSON.stringify(e);
|
try {
|
||||||
|
return JSON.stringify(e);
|
||||||
|
} catch (e) {
|
||||||
|
// Stringify might fail on arbitrary structures
|
||||||
|
// Last resort: toString it.
|
||||||
|
return '' + e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user