import {FetchAdapterResponse, RequestMeta} from "../fetchAdapter";

export declare interface BaseErrorParams {
    response: FetchAdapterResponse,
    request: Request,
    requestMeta?: RequestMeta,
    message: string,
    code: number,
    stack?: string,
    cause?: Error
}

export class BaseError extends Error {
    public response: FetchAdapterResponse
    public request: Request
    public requestMeta?: RequestMeta
    public code: number

    constructor(params: BaseErrorParams) {
        super();

        this.response = params.response
        this.request = params.request
        this.requestMeta = params.requestMeta
        this.message = params.message
        this.code = params.code
        this.cause = params.cause ?? this.cause
        this.stack = params.stack ?? this.stack
    }
}
