fix(mixins/Tasks): correctly serialize errors
This commit is contained in:
@@ -14,6 +14,15 @@ const formatId = timestamp => timestamp.toString(36).padStart(9, '0')
|
||||
|
||||
const noop = Function.prototype
|
||||
|
||||
// Create a serializable object from an error.
|
||||
const serializeError = error => ({
|
||||
...error, // Copy enumerable properties.
|
||||
code: error.code,
|
||||
message: error.message,
|
||||
name: error.name,
|
||||
stack: error.stack,
|
||||
})
|
||||
|
||||
export default class Tasks extends EventEmitter {
|
||||
// contains consolidated logs of all live and finished tasks
|
||||
#store
|
||||
@@ -27,6 +36,12 @@ export default class Tasks extends EventEmitter {
|
||||
this.#tasks.delete(id)
|
||||
},
|
||||
onTaskUpdate: async taskLog => {
|
||||
// Error objects are not JSON-ifiable by default
|
||||
const { result } = taskLog
|
||||
if (result instanceof Error && result.toJSON === undefined) {
|
||||
taskLog.result = serializeError(result)
|
||||
}
|
||||
|
||||
try {
|
||||
const { $root } = taskLog
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
<!--packages-start-->
|
||||
|
||||
- @xen-orchestra/mixins patch
|
||||
- xo-cli minor
|
||||
- xo-web minor
|
||||
|
||||
|
||||
Reference in New Issue
Block a user