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

View File

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

View File

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