UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines 1.04 kB
import{isObject}from"#shared/guards.js";import{walkCauseChain}from"#shared/errors.js";function extractErrorSignals(e){let t=[];for(let n of walkCauseChain(e)){if(!isObject(n))continue;let e={message:typeof n.message==`string`?n.message:``};typeof n.name==`string`&&n.name.length>0&&(e.name=n.name),typeof n.code==`string`&&n.code.length>0&&(e.code=n.code),typeof n.statusCode==`number`&&(e.statusCode=n.statusCode);let r=readGatewayType(n);r!==void 0&&(e.type=r),typeof n.hint==`string`&&n.hint.length>0&&(e.hint=n.hint),t.push(e)}return{chain:t}}function readGatewayType(e){if(typeof e.type==`string`&&e.type.length>0)return e.type;let t=readGatewayTypeFromBody(e.data);if(t!==void 0)return t;if(typeof e.responseBody==`string`)try{return readGatewayTypeFromBody(JSON.parse(e.responseBody))}catch{return}}function readGatewayTypeFromBody(e){if(!isObject(e))return;let t=e.error;return isObject(t)&&typeof t.type==`string`?t.type.length>0?t.type:void 0:typeof e.type==`string`&&e.type.length>0?e.type:void 0}export{extractErrorSignals};