@@ -745,7 +745,54 @@ Errors returned by the library have a `code` property which contains the program
745745To avoid typos, you can use the `ErrorCode` enum to refer to the codes.
746746
747747**Example**
748+ The `examples` directory contains fully working applications demonstrating authentication and digital signing.
749+
750+ There is two approaches to handle errors:
748751```ts
752+ // by Error instance
753+ const onLogin = async () => {
754+ setLoading(true)
755+ setAlert(undefined)
756+
757+ try {
758+ await loginWithIdCard()
759+ navigate(' /sign' )
760+ } catch (error) {
761+ if (error instanceof UserTimeoutError) {
762+ setAlert("ID-card authentication timed out, please try again");
763+ } else if (error instanceof UserCancelledError) {
764+ setAlert("ID-card authentication was cancelled by the user");
765+ } else if (error instanceof ExtensionUnavailableError) {
766+ setAlert("Web eID browser extension is not available, please install it or enable it to continue");
767+ } else if (error instanceof NativeUnavailableError) {
768+ setAlert("Web eID native application is not installed, please install it to continue");
769+ } else if (error instanceof VersionInvalidError) {
770+ setAlert("Web eID native application did not provide a valid version string during handshake, please report a bug");
771+ } else if (error instanceof VersionMismatchError) {
772+ if (error.requiresUpdate?.extension) {
773+ setAlert("Please update the Web eID browser extension");
774+ } else if (error.requiresUpdate?.nativeApp) {
775+ setAlert("Please update the Web eID native application");
776+ } else {
777+ setAlert("Please update the Web eID native application and browser extension");
778+ }
779+ } else if (error instanceof ContextInsecureError) {
780+ setAlert("Web eID requires a secure HTTPS connection. Please contact the website administrator");
781+ } else if (error instanceof NativeFatalError) {
782+ setAlert("Please try again. If the problem persists, contact support");
783+ } else if (error instanceof UnknownError) {
784+ setAlert(`An unknown error occurred. Please try again and contact support if the problem persists! ${error.message} (${error.code})`);
785+ } else {
786+ const errorMessage = error instanceof Error ? error.message : String(error);
787+ const errorCode = isKnownWebEidError(error) ? ` (${(error as any).code})` : "";
788+ setAlert(`An unknown error occurred. Please try again and contact support if the problem persists! ${errorMessage}${errorCode}`);
789+ }
790+
791+ } finally {
792+ setLoading(false)
793+ }
794+ }
795+ // Or by Error.code
749796try {
750797 const {
751798 certificate,
@@ -760,7 +807,6 @@ try {
760807 showError("Signing certificate retrieval timed out, please try again!");
761808 break;
762809 }
763-
764810 // other cases
765811
766812 default: {
0 commit comments