Skip to content

Commit

Permalink
fix(expo-offline-support): Add Handling network errors section
Browse files Browse the repository at this point in the history
  • Loading branch information
anagstef committed Dec 13, 2024
1 parent ce044c3 commit b9ed5a8
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions docs/references/expo/offline-support.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,45 @@ To enable offline support in your Expo app, follow these steps:
}
```
</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 (
<View>
<Button title="Sign in" onPress={onSignInPress} />
</View>
)
}
```

0 comments on commit b9ed5a8

Please sign in to comment.