Skip to content

Commit

Permalink
fix(DHIS2-15304): display correct error message when session is expired
Browse files Browse the repository at this point in the history
  • Loading branch information
kabaros committed Dec 12, 2023
1 parent f40f287 commit 2b4e162
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useConfig } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'

class Api {
constructor({ baseUrl }) {
Expand All @@ -10,7 +11,15 @@ class Api {
method,
body,
credentials: 'include',
redirect: 'manual',
}).then(async (res) => {
if (res.type === 'opaqueredirect') {
throw {
message: i18n.t(
'Your session has expired. Please refresh the page and login before trying again.'
),
}
}
if (res.status < 200 || res.status >= 300) {
const errorBody = await res.json()
throw errorBody
Expand Down

0 comments on commit 2b4e162

Please sign in to comment.