File size: 638 Bytes
1477a90 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
import { HTTPError as KyHTTPError } from 'ky'
import * as schemas from '../models/schemas.js'
import { HTTPError } from '../models/errors.js'
export async function toError(e: unknown): Promise<Error> {
if (e instanceof KyHTTPError) {
// ky consumes the body into e.data; e.response.json() would throw.
const parsed = schemas.baseError.safeParse(e.data)
const error = parsed.success ? parsed.data : undefined
return HTTPError.fromResponse({ response: e.response, error })
}
if (e instanceof Error) {
return e
}
return new Error(String(e))
}
|