UNPKG

@beignet/core

Version:

Core framework primitives for Beignet

34 lines 1.02 kB
/** * Standard error response schema and utilities for Beignet */ /** * Create a standard error response body and omit undefined optional fields. */ export function createErrorResponseBody(args) { return { code: args.code, message: args.message, ...(args.details !== undefined ? { details: args.details } : {}), ...(args.requestId !== undefined ? { requestId: args.requestId } : {}), }; } /** * Check whether a value looks like a standard Beignet error response body. */ export function isErrorResponseBody(value) { if (typeof value !== "object" || value === null) return false; const body = value; return typeof body.code === "string" && typeof body.message === "string"; } /** * Convert an `AppError` to a standard error response body. */ export function toErrorResponseBody(err) { return createErrorResponseBody({ code: err.code, message: err.message, details: err.details, }); } //# sourceMappingURL=response.js.map