blujosiB
Convex Community14mo ago
2 replies
blujosi

Error in return types

I am getting the error below
Uncaught Error: Result {"data":"undefined","error":"Unauthorized"}

when i call a query or a mutation simply because i am returning a Result type
export class Result<T> {
    constructor(
        public readonly data?: T,
        public readonly error?: string
    ) {}

    get isOk(): boolean {
        return this.error === undefined
    }

    static success<T>(data: T): Result<T> {
        return new Result(data)
    }

    static failure<T>(error: Error): Result<T> {
        console.log('error', error)
        return new Result<T>(undefined, error?.message)
    }
}

i do not want to throw in any case and handle the response in the calling application .
Was this page helpful?