Update de/serializeError functions to only serialize data if present (#1849)

This commit is contained in:
toasted-nutbread 2021-07-25 12:54:26 -04:00 committed by GitHub
parent 73f06a3fa0
commit 3f73889874
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 10 deletions

View File

@ -23,12 +23,15 @@
function serializeError(error) { function serializeError(error) {
try { try {
if (typeof error === 'object' && error !== null) { if (typeof error === 'object' && error !== null) {
return { const result = {
name: error.name, name: error.name,
message: error.message, message: error.message,
stack: error.stack, stack: error.stack
data: error.data
}; };
if (Object.prototype.hasOwnProperty.call(error, 'data')) {
result.data = error.data;
}
return result;
} }
} catch (e) { } catch (e) {
// NOP // NOP
@ -51,7 +54,9 @@ function deserializeError(serializedError) {
const error = new Error(serializedError.message); const error = new Error(serializedError.message);
error.name = serializedError.name; error.name = serializedError.name;
error.stack = serializedError.stack; error.stack = serializedError.stack;
error.data = serializedError.data; if (Object.prototype.hasOwnProperty.call(serializedError, 'data')) {
error.data = serializedError.data;
}
return error; return error;
} }

View File

@ -72,12 +72,15 @@ class TemplateRendererFrameApi {
_serializeError(error) { _serializeError(error) {
try { try {
if (typeof error === 'object' && error !== null) { if (typeof error === 'object' && error !== null) {
return { const result = {
name: error.name, name: error.name,
message: error.message, message: error.message,
stack: error.stack, stack: error.stack
data: error.data
}; };
if (Object.prototype.hasOwnProperty.call(error, 'data')) {
result.data = error.data;
}
return result;
} }
} catch (e) { } catch (e) {
// NOP // NOP

View File

@ -92,12 +92,15 @@ async function createVM() {
_serializeError(error) { _serializeError(error) {
try { try {
if (typeof error === 'object' && error !== null) { if (typeof error === 'object' && error !== null) {
return { const result = {
name: error.name, name: error.name,
message: error.message, message: error.message,
stack: error.stack, stack: error.stack
data: error.data
}; };
if (Object.prototype.hasOwnProperty.call(error, 'data')) {
result.data = error.data;
}
return result;
} }
} catch (e) { } catch (e) {
// NOP // NOP