Skip to content

Commit

Permalink
fix: returns meaningful errors
Browse files Browse the repository at this point in the history
Previously the only error it would catch was network errors. I've added a few other possibilities
  • Loading branch information
kiwicopple committed Oct 15, 2020
1 parent 8d9dea5 commit 1207790
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
11 changes: 5 additions & 6 deletions example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ function App() {
useEffect(() => {
setSession(auth.currentSession)
auth.onAuthStateChange((_event, session) => setSession(session))
console.log('auth.currentUser', auth.currentUser)
}, [])

async function handleOAuthLogin(provider) {
let { error } = await auth.signIn({ provider })
if (error) console.log('error', error.message)
if (error) console.log('Error: ', error.message)
}
async function handleEmailSignIn() {
if (rememberMe) {
Expand All @@ -27,15 +26,15 @@ function App() {
localStorage.removeItem('email');
}
let { error } = await auth.signIn({ email, password })
if (error) console.log('error', error.message)
if (error) console.log('Error: ', error.message)
}
async function handleEmailSignUp() {
let { error } = await auth.signUp({ email, password })
if (error) console.log('error', error.message)
if (error) console.log('Error: ', error.message)
}
async function handleSignOut() {
let { error } = await auth.signOut()
if (error) console.log('error', error.message)
if (error) console.log('Error: ', error.message)
}
async function forgotPassword() {
var email = prompt("Please enter your email:");
Expand All @@ -44,7 +43,7 @@ function App() {
} else {
let { data, error } = auth.api.resetPasswordForEmail(email);
if (error) {
console.log('error', error.message);
console.log('Error: ', error.message)
} else {
alert(data)
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export interface FetchOptions {
const handleError = (error: any, reject: any) => {
if (typeof error.json === 'function') {
error.json().then((msg: any) => {
return reject(new Error(msg.error_description))
let errorMessage = msg.message || msg.error_description || msg.error || JSON.stringify(msg)
return reject(new Error(errorMessage))
})
} else {
return reject(error)
Expand Down

0 comments on commit 1207790

Please sign in to comment.