Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚸 Improve Error Handling #382

Merged
merged 1 commit into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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