i.sona
i.sona2w ago

Error in return types

I am getting the error below
Uncaught Error: Result {"data":"undefined","error":"Unauthorized"}
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)
}
}
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 .
2 Replies
Convex Bot
Convex Bot2w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
i.sona
i.sonaOP2w ago
No worries , Fixed it by changing class to object and defining type for it

Did you find this page helpful?