refactor: cleanup web-frame-init.js (#14516)
* refactor: add error-utils.js * fix exception handling for asyncWebFrameMethods * remove dead code * handle exceptions * rename rehydratedError to deserializedError * Revert "handle exceptions" This reverts commit 396b179948b137f9e525e9ebba4f7c6e9bf19429.
This commit is contained in:
parent
38419e3a6a
commit
0821edc843
4 changed files with 53 additions and 65 deletions
35
lib/common/error-utils.js
Normal file
35
lib/common/error-utils.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
'use strict'
|
||||
|
||||
const constructors = new Map([
|
||||
[Error.name, Error],
|
||||
[EvalError.name, EvalError],
|
||||
[RangeError.name, RangeError],
|
||||
[ReferenceError.name, ReferenceError],
|
||||
[SyntaxError.name, SyntaxError],
|
||||
[TypeError.name, TypeError],
|
||||
[URIError.name, URIError]
|
||||
])
|
||||
|
||||
exports.deserialize = function (error) {
|
||||
if (error.__ELECTRON_SERIALIZED_ERROR__ && constructors.has(error.name)) {
|
||||
const constructor = constructors.get(error.name)
|
||||
const deserializedError = new constructor(error.message)
|
||||
deserializedError.stack = error.stack
|
||||
return deserializedError
|
||||
}
|
||||
return error
|
||||
}
|
||||
|
||||
exports.serialize = function (error) {
|
||||
if (error instanceof Error) {
|
||||
// Errors get lost, because: JSON.stringify(new Error('Message')) === {}
|
||||
// Take the serializable properties and construct a generic object
|
||||
return {
|
||||
message: error.message,
|
||||
stack: error.stack,
|
||||
name: error.name,
|
||||
__ELECTRON_SERIALIZED_ERROR__: true
|
||||
}
|
||||
}
|
||||
return error
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue