Accept an async listener in the types and normalise any rejection reason
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
/** Whatever was thrown or rejected, as an Error. `String()` throws on some values; this cannot. */
|
||||
export function errorFrom(reason: unknown): Error {
|
||||
if (reason instanceof Error) return reason;
|
||||
|
||||
try {
|
||||
return new Error(String(reason));
|
||||
} catch {
|
||||
return new Error('A thrown value that cannot be converted to a string');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user