Function: mapErrorToApiResponse() ​
mapErrorToApiResponse(
error):object
Defined in: packages/errors/src/index.ts:118
Maps an error to an API error response object. Use with a JSON response helper (e.g., SvelteKit's json()).
Parameters ​
error ​
unknown
The error to map
Returns ​
object
Object containing the response body and HTTP status
body ​
body:
ApiErrorResponse
status ​
status:
number
Example ​
typescript
import { json } from '@sveltejs/kit';
try {
// ... operation
} catch (error) {
const { body, status } = mapErrorToApiResponse(error);
return json(body, { status });
}