Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding method error support #46

Closed
wants to merge 1 commit into from
Closed

Adding method error support #46

wants to merge 1 commit into from

Conversation

L-Marcel
Copy link

Hi! I tried to create an approach to detect errors and I got the following result:

Captura de tela 2023-01-20 180807

I created a folder with a new test as well:
image

Method example:

export async function getInfo(authorized: boolean): Promise<HostInfo> {
  if(!authorized) {
    return apiError(401, "Hey! You need to be authorized!", {
      requestedAt: new Date().toLocaleTimeString()
    });
  };

  return {
    now: new Date().toLocaleTimeString(),
    hostname: os.hostname(),
  };
}

Use case example:

React.useEffect(() => {
  const interval = setInterval(() => {
    getInfo(true).then(res => setInfo(res));
    getInfo(false).catch((err: RPCMethodError) => setError(err));
  }, 2000);
  return () => clearInterval(interval);
}, []);

Related issues: #19

Note: sorry for my English. I'm Brazilian. I thought the idea was amazing!

@L-Marcel
Copy link
Author

I used npm link ../../ in "./examples/with-error" to run the example with the local version.

@L-Marcel L-Marcel closed this by deleting the head repository Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant