perun-network / erdstall-ts-sdk

TypeScript client SDK to interact with Erdstall.
Apache License 2.0
5 stars 2 forks source link

Investigate error reporting and checking without losing stacktraces #78

Open ndzik opened 3 years ago

ndzik commented 3 years ago

As mentioned in https://github.com/perun-network/erdstall-ts-sdk/pull/69#discussion_r701865821, we are not really sure how to properly expose errors thrown by our SDK.

IMO, it would be ideal if we could allow users to do the following:

try {
    // some awesome SDK functions/methods used.
} catch (e) {
    switch (sdk.asErdstallError(e)) {
        case "Connection": // Handle connection error.
        case "Signature": // Handle signature error.
    }
    // Standard way to handle errors.
}

I realise this is opinionated, but I really dislike the way errors have to be checked in "default" TS. Finding a trusted and battletested library which could be used to take some burden off of the user and guiding them to properly handle exceptions/errors is beneficial in the long run.