import type { AnyElysia } from 'elysia' import type { Range } from './utils/types' export class EdenFetchError extends Error { constructor( public status: Status, public value: Value, ) { super(value + '') } } export class EdenFatalError extends Error { static throw() { return new EdenFatalError() } constructor() { super( 'Something went wrong. Please submit an issue at https://github.com/aydee-app/eden-query/issues/new', ) } } export type MapError> = [ { [K in keyof T]-?: K extends ErrorRange ? K : never }[keyof T], ] extends [infer A extends number] ? { [K in A]: EdenFetchError }[A] : false export type ErrorRange = Range<300, 599> /** * Type representing any error-like object that can be thrown by Eden client operations. * This includes EdenFetchError instances with any status code and value. * * @template _T - The Elysia app type (reserved for future use with route-specific error types) */ export type EdenClientErrorLike<_T extends AnyElysia = AnyElysia> = | EdenFetchError | Error export const ERROR_SYMBOL = Symbol('TypeError') export type TypeError = TMessage & { _: typeof ERROR_SYMBOL }