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

Ambiguous error handling in NWC #288

Open
riccardobl opened this issue Dec 3, 2024 · 0 comments
Open

Ambiguous error handling in NWC #288

riccardobl opened this issue Dec 3, 2024 · 0 comments

Comments

@riccardobl
Copy link

NDKNWCResponseBase defines an error field

export interface NDKNWCResponseBase<T = any> {
result_type: NDKNWCMethod;
error?: {
code: NDKNWCErrorCode;
message: string;
};
result: T | null;
}

however this is not used, instead the whole response (not just the error) is passed to the reject arguments of the promise

reject(content);

This makes it pretty ambiguous implementation wise.
It would be better to remove the error fields from NDKNWCResponseBase, if it is unused, and wrap the error on a stringifieable object that implements Error, so it can be handled like any other throwable error.

This ambiguity seems to have affected also the internal code here , and in some other places,

if (res.error) throw new Error(res.error.message);

where there is this rethrow that is never reached, since the error is thrown and not returned by req

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

No branches or pull requests

1 participant