chore(orchestration): serialize error (#6967)
This commit is contained in:
@@ -45,3 +45,30 @@ export class TransactionTimeoutError extends Error {
|
||||
this.name = "TransactionTimeoutError"
|
||||
}
|
||||
}
|
||||
|
||||
export function serializeError(error) {
|
||||
const serialized = {
|
||||
message: error.message,
|
||||
name: error.name,
|
||||
stack: error.stack,
|
||||
}
|
||||
|
||||
Object.getOwnPropertyNames(error).forEach((key) => {
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
if (!serialized.hasOwnProperty(key)) {
|
||||
serialized[key] = error[key]
|
||||
}
|
||||
})
|
||||
|
||||
return serialized
|
||||
}
|
||||
|
||||
export function isErrorLike(value) {
|
||||
return (
|
||||
!!value &&
|
||||
typeof value === "object" &&
|
||||
"name" in value &&
|
||||
"message" in value &&
|
||||
"stack" in value
|
||||
)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@ import {
|
||||
import { MedusaError, promiseAll, TransactionStepState } from "@medusajs/utils"
|
||||
import { EventEmitter } from "events"
|
||||
import {
|
||||
isErrorLike,
|
||||
PermanentStepFailureError,
|
||||
serializeError,
|
||||
TransactionStepTimeoutError,
|
||||
TransactionTimeoutError,
|
||||
} from "./errors"
|
||||
@@ -479,6 +481,10 @@ export class TransactionOrchestrator extends EventEmitter {
|
||||
): Promise<void> {
|
||||
step.failures++
|
||||
|
||||
if (isErrorLike(error)) {
|
||||
error = serializeError(error)
|
||||
}
|
||||
|
||||
if (
|
||||
!isTimeout &&
|
||||
step.getStates().status !== TransactionStepStatus.PERMANENT_FAILURE
|
||||
|
||||
Reference in New Issue
Block a user