Skip to content

Commit

Permalink
refactor(errors): change errors handling into more user friendly (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
WojtekBinkowski authored Jul 18, 2023
1 parent 3957bad commit a7976db
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 13 deletions.
10 changes: 7 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,19 @@ export const App = () => {
}
})
.catch((error) => {
let errorMsg
if (error.response.status === 401 || error.response.status === 400) {
setAuthorization(null)
navigate('/')
setLoading(false)
return
}
const errorMsg = error.response.data.error
? error.response.data.error
: 'Something went wrong... Please, try again later!'

if (error.response.status === 404) {
errorMsg = error.response.data + ". If you can't log in again, please contact our support or try again later!"
} else {
errorMsg = error.response.data ? error.response.data : 'Something went wrong... Please, try again later!'
}

setError(errorMsg)
setLoading(false)
Expand Down
11 changes: 9 additions & 2 deletions src/components/AccountSummary/AccountSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ export const AccountSummary = () => {
setDetails(accountDetails)
})
.catch((error) => {
if (error) {
setErrors('Something went wrong... Please, try again later!')
let errorMsg

if (error.response.status === 404) {
errorMsg =
"User's account details not found. If you can't log in again, please contact our support or try again later!"
} else {
errorMsg = error.response.data ? error.response.data : 'Something went wrong... Please, try again later!'
}

setErrors(errorMsg)
})
.finally(() => {
setLoading(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export const TransactionConfirmModal: FC<TransactionConfirmModalProps> = ({
}

setErrors(
'Transfer was not sent. Please verify transfer data and try once again. If problem will happen again, contact with our support.'
error.response.data
? error.response.data
: 'Transfer was not sent. Please verify transfer data and try once again. If problem will happen again, contact with our support.'
)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export const TransactionDetailsModal: FC<TransactionDetailsProps> = ({ open, pri
setTransactionData(response)
})
.catch((error) => {
error && setErrors('Something went wrong... Please try again later')
const errorMsg = error.response.data ? error.response.data : 'Something went wrong... Please try again later'
errorMsg && setErrors(errorMsg)
})
.finally(() => {
setLoading(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const TransactionTable = () => {
setLoading(false)
})
.catch((error) => {
setErrors(error)
const errorMsg = error.response.data ? error.response.data : 'Something went wrong... Please try again later'
setErrors(errorMsg)
})
.finally(() => setLoading(false))
}, [currentPage, autoupdate])
Expand All @@ -76,7 +77,7 @@ export const TransactionTable = () => {
{!transactionsList ? (
<NoDataInfo>No transaction yet</NoDataInfo>
) : errors ? (
<ErrorBar errorMsg="Something went wrong... Please try again later" withReloadButton />
<ErrorBar errorMsg={errors} withReloadButton />
) : (
<Table>
<thead>
Expand Down
3 changes: 2 additions & 1 deletion src/components/UserMenu/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export const UserMenu: FC<MenuProps> = ({ userEmail }) => {
Navigate('/')
})
.catch((error) => {
error && setErrors('Something went wrong... Please try again!')
const errorMsg = error.response.data ? error.response.data : 'Something went wrong... Please try again!'
errorMsg && setErrors(errorMsg)
})
.finally(() => {
setLoading(false)
Expand Down
4 changes: 1 addition & 3 deletions src/views/SignupPage/SignupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ export const SignupPage = () => {
setLoading(false)
})
.catch((error) => {
const errorMsg = error.response.data.error
? error.response.data.error
: 'Something went wrong... Please, try again later!'
const errorMsg = error.response.data ? error.response.data : 'Something went wrong... Please, try again later!'
setErrors(errorMsg)
setRegistered(false)
setLoading(false)
Expand Down

0 comments on commit a7976db

Please sign in to comment.