Skip to content

safe API - rename isDefined to isDefinedError for readability #1385

@tresorama

Description

@tresorama

Describe the feature

No big deal, but I would prefer it.

Current

const orpcClient = ...
const orpcClientSafe = ... 

const result = await orpcClientSafe.demoPost.getAllPosts();
// or 
const result = await safe(orpcClient.demoPost.getAllPosts());

if (!result.isSuccess) {
 if (result.isDefined && result.error.code === 'POST_NOT_FOUND') {
   // handle this case
 }
 // rethrow the error if unknown
 throw result.error;
}

const post = result.data.data.post;

Request

const orpcClient = ...
const orpcClientSafe = ... 

const result = await orpcClientSafe.demoPost.getAllPosts();
// or 
const result = await safe(orpcClient.demoPost.getAllPosts());

if (!result.isSuccess) {
 //             👇
 if (result.isDefinedError && result.error.code === 'POST_NOT_FOUND') {
   // handle this case
 }
 // rethrow the error if unknown
 throw result.error;
}

const post = result.data.data.post;

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions