@@ -49,13 +49,16 @@ export function buildBlockExecutionError(details: BlockExecutionErrorDetails): E
4949
5050 const error = new Error ( `${ blockName } : ${ errorMessage } ` )
5151
52+ const innerStatusCode = readStatusCode ( details . error )
53+
5254 Object . assign ( error , {
5355 blockId : details . block . id ,
5456 blockName,
5557 blockType,
5658 workflowId : details . context ?. workflowId ,
5759 timestamp : new Date ( ) . toISOString ( ) ,
5860 ...details . additionalInfo ,
61+ ...( innerStatusCode !== undefined ? { statusCode : innerStatusCode } : { } ) ,
5962 } )
6063
6164 return error
@@ -89,6 +92,25 @@ export function buildHTTPError(config: {
8992 return error
9093}
9194
95+ function readStatusCode ( value : unknown ) : number | undefined {
96+ if ( ! ( value instanceof Error ) ) return undefined
97+ const status = ( value as unknown as { statusCode ?: unknown } ) . statusCode
98+ return typeof status === 'number' ? status : undefined
99+ }
100+
101+ /**
102+ * Maps an execution error to an HTTP status code. Errors thrown from the
103+ * executor that represent workflow-author mistakes (invalid field references,
104+ * etc.) carry a 4xx `statusCode`; everything else is a 500.
105+ */
106+ export function getExecutionErrorStatus ( error : unknown ) : number {
107+ const status = readStatusCode ( error )
108+ if ( status !== undefined && status >= 400 && status < 500 ) {
109+ return status
110+ }
111+ return 500
112+ }
113+
92114export function normalizeError ( error : unknown ) : string {
93115 if ( error instanceof Error ) {
94116 return error . message
0 commit comments