From b9ed5a80858c3363fd045c9244674ff965f44bb9 Mon Sep 17 00:00:00 2001 From: Stefanos Anagnostou Date: Fri, 13 Dec 2024 21:16:16 +0200 Subject: [PATCH] fix(expo-offline-support): Add `Handling network errors` section --- docs/references/expo/offline-support.mdx | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/docs/references/expo/offline-support.mdx b/docs/references/expo/offline-support.mdx index a281071efa..75a087ef17 100644 --- a/docs/references/expo/offline-support.mdx +++ b/docs/references/expo/offline-support.mdx @@ -71,3 +71,45 @@ To enable offline support in your Expo app, follow these steps: } ``` + +## Handling network errors + +To handle network errors in your Expo app, you can use the `isClerkRuntimeError` function alongside the `code` property to identify the specific error. Here's an example of how you can handle network errors: + +```tsx {{ mark: [1, [24, 26]] }} +import { isClerkRuntimeError } from '@clerk/clerk-js' +import { useSignIn } from '@clerk/clerk-expo' +import { Link, useRouter } from 'expo-router' +import { Text, TextInput, Button, View } from 'react-native' +import React from 'react' + +export default function SignInPage() { + const { signIn, setActive, isLoaded } = useSignIn() + const router = useRouter() + + const [emailAddress, setEmailAddress] = React.useState('') + const [password, setPassword] = React.useState('') + + const onSignInPress = React.useCallback(async () => { + if (!isLoaded) return + try { + const signInAttempt = await signIn.create({ + identifier: emailAddress, + password, + }) + + // more logic here + } catch (err) { + if (isClerkRuntimeError(err) && err.code === 'network_error') { + console.error('Network error occurred!') + } + } + }, [isLoaded, emailAddress, password]) + + return ( + +