Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 120
max_line_length = 160
quote_type = double

[*.md]
trim_trailing_whitespace = false
54 changes: 52 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,57 @@ Errors returned by the library have a `code` property which contains the program
To avoid typos, you can use the `ErrorCode` enum to refer to the codes.

**Example**
The `examples` directory contains fully working applications demonstrating authentication and digital signing.

There is two approaches to handle errors:
```ts
// by Error instance
const onLogin = async () => {
setLoading(true)
setAlert(undefined)

try {
await loginWithIdCard()
navigate('/sign')
} catch (error) {
if (error instanceof UserTimeoutError) {
setAlert("ID-card authentication timed out, please try again");
} else if (error instanceof UserCancelledError) {
setAlert("ID-card authentication was cancelled by the user");
} else if (error instanceof ExtensionUnavailableError) {
setAlert("Web eID browser extension is not available, please install it or enable it to continue");
} else if (error instanceof NativeUnavailableError) {
setAlert("Web eID native application is not installed, please install it to continue");
} else if (error instanceof VersionInvalidError) {
setAlert("Web eID native application did not provide a valid version string during handshake, please report a bug");
} else if (error instanceof VersionMismatchError) {
if (error.requiresUpdate?.extension) {
setAlert("Please update the Web eID browser extension");
} else if (error.requiresUpdate?.nativeApp) {
setAlert("Please update the Web eID native application");
} else {
setAlert("Please update the Web eID native application and browser extension");
}
} else if (error instanceof ContextInsecureError) {
setAlert("Web eID requires a secure HTTPS connection. Please contact the website administrator");
} else if (error instanceof NativeFatalError) {
setAlert("Please try again. If the problem persists, contact support");
} else if (error instanceof IntegrationError) {
setAlert(`An internal error occurred. Please contact support! ${error.message} (${error.code})`);
} else if (error instanceof UnknownError) {
setAlert(`An unknown error occurred. Please try again and contact support if the problem persists! ${error.message} (${error.code})`);
} else {
const errorMessage = error instanceof Error ? error.message : String(error);
const errorCode = isKnownWebEidError(error) ? ` (${(error as any).code})` : "";
setAlert(`An unknown error occurred. Please try again and contact support if the problem persists! ${errorMessage}${errorCode}`);
}

} finally {
setLoading(false)
}
}

// Or by Error.code
try {
const {
certificate,
Expand All @@ -760,9 +810,9 @@ try {
showError("Signing certificate retrieval timed out, please try again!");
break;
}

// other cases

default: {
showError(
"An unknown error occurred. " +
Expand Down
18 changes: 14 additions & 4 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ const overrides = {
rules: {
"sort-imports": ["error", { allowSeparatedGroups: true }],

"@stylistic/js/quotes": "error",
"@stylistic/js/quotes": ["error", "double"],
"@stylistic/js/key-spacing": ["error", { "align": "value" }],
"@stylistic/js/comma-dangle": ["error", "always-multiline"],
"@stylistic/js/object-curly-spacing": ["error", "always"],
"@stylistic/js/array-bracket-spacing": "error",
"@stylistic/js/indent": ["error", 2, { "SwitchCase": 1 }],
"@stylistic/js/semi": "error",
"@stylistic/js/eol-last": ["warn", "always"],
"@stylistic/js/linebreak-style": ["error", "unix"],
"@stylistic/js/max-len": ["error", { code: 160 }],
},
},

Expand All @@ -74,14 +77,21 @@ const overrides = {
},

rules: {
"@typescript-eslint/array-type": ["error", { default: "generic" }],
"@stylistic/ts/semi": "error",
"@typescript-eslint/array-type": ["error", { default: "generic" }],
"@stylistic/ts/semi": "error",
"@stylistic/ts/quotes": ["error", "double"],
"@stylistic/ts/comma-dangle": ["error", "always-multiline"],
"@stylistic/ts/object-curly-spacing": ["error", "always"],
"@stylistic/ts/indent": ["error", 2, { "SwitchCase": 1 }],
"@stylistic/ts/eol-last": ["error", "always"],
"@stylistic/ts/linebreak-style": ["error", "unix"],
"@stylistic/ts/max-len": ["error", { code: 160 }],
},
},
};

export default [
{ ignores: ["dist/", "node_modules/"] },
{ ignores: ["dist/", "node_modules/", "examples/"] },

{
name: "eslint/recommended",
Expand Down
Loading
Loading