Skip to content

Commit

Permalink
Merge pull request #382 from systemli/improve-error-handling
Browse files Browse the repository at this point in the history
🚸 Improve Error Handling
  • Loading branch information
0x46616c6b authored Oct 9, 2022
2 parents 19131b8 + 72468e7 commit 4600f30
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/settings/InactiveSettingsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const InactiveSettingsCard: FC = () => {
)
}

if (error || data === undefined) {
if (error || data === undefined || data.status === 'error') {
return <ErrorView>Unable to fetch inactive settings from server.</ErrorView>
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/settings/RefreshIntervalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const RefreshIntervalCard: FC = () => {
)
}

if (error || data === undefined) {
if (error || data === undefined || data.status === 'error') {
return (
<ErrorView>
Unable to fetch refresh interval setting from server.
Expand Down
9 changes: 8 additions & 1 deletion src/components/useAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ export function AuthProvider({
return
}

const user = decode(token) as User
let user: User
try {
user = decode(token) as User
} catch (error) {
setError(error)
setLoadingInitial(false)
return
}
const now = Math.floor(new Date().getTime() / 1000)

if (user.exp > now) {
Expand Down
11 changes: 9 additions & 2 deletions src/components/useFeature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,22 @@ export function FeatureProvider({
const { getFeatures } = useFeatureApi(token)

useEffect(() => {
if (token === '') {
setLoadingInitial(false)
return
}

getFeatures()
.then(response => {
setFeatures(response.data.features)
if (response.status === 'success') {
setFeatures(response.data.features)
}
})
.finally(() => {
setLoadingInitial(false)
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
}, [token])

const memoedValue = useMemo(
() => ({
Expand Down
2 changes: 1 addition & 1 deletion src/components/user/UserList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const UserList: FC = () => {
)
}

if (error || data === undefined) {
if (error || data === undefined || data.status === 'error') {
return <ErrorView>Unable to fetch users from server.</ErrorView>
}

Expand Down
2 changes: 1 addition & 1 deletion src/views/HomeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const HomeView: FC = () => {
)
}

if (error || data === undefined) {
if (error || data === undefined || data.status === 'error') {
return (
<Layout>
<ErrorView>Unable to fetch tickers from server.</ErrorView>
Expand Down
2 changes: 1 addition & 1 deletion src/views/TickerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const TickerView: FC = () => {
return <Loader size="large" />
}

if (error || data === undefined) {
if (error || data === undefined || data.status === 'error') {
return <ErrorView>Unable to fetch the ticker from server.</ErrorView>
}

Expand Down

0 comments on commit 4600f30

Please sign in to comment.