openwallet-foundation-labs / sd-jwt-js

A JavaScript implementation of the Selective Disclosure JWT (SD-JWT) spec.
https://sdjwt.js.org/
Apache License 2.0
36 stars 11 forks source link

Define error messages as exportable constants #241

Open cre8 opened 3 months ago

cre8 commented 3 months ago

Sometimes we need to find out which error was thrown. To avoid a break of our application when we change the string of the error message, we should use constants that we use for throwing an error and that can be used by a developper for checking it like

const STATUS_NOT_VALID = "Status is not valid";
...
throw new Error(STATUS_NOT_VALID)
...
catch(e) {
if(e.message === STATUS_NOT_VALID)
}
lukasjhan commented 3 months ago

It's a good idea.

Since the error message variables may be the same, let's include the namespace with it. such as:

catch(e) {
    if(e.message === SD_JWT_ERROR.STATUS_NOT_VALID)
}