Skip to content

Commit

Permalink
käsitellään http 401
Browse files Browse the repository at this point in the history
  • Loading branch information
marjakari committed Jan 24, 2024
1 parent f4ee2b6 commit 8de7cc5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion viestinvalitys-raportointi/src/app/lib/data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { headers } from 'next/headers'
import { LahetysHakuParams } from './types'
import { apiUrl } from './configurations'
import { apiUrl, loginUrl } from './configurations'
import { redirect } from 'next/navigation'

// TODO apuwrapperi headerien asettamiseen
export async function fetchLahetykset(hakuParams: LahetysHakuParams) {
Expand All @@ -14,6 +15,9 @@ export async function fetchLahetykset(hakuParams: LahetysHakuParams) {
})
console.info(res.status)
if (!res.ok) {
if(res.status===401) {
redirect(loginUrl)
}
// This will activate the closest `error.js` Error Boundary
throw new Error('Failed to fetch data')
}
Expand All @@ -29,6 +33,9 @@ export async function fetchLahetykset(hakuParams: LahetysHakuParams) {
})
console.log(res.status)
if (!res.ok) {
if(res.status===401) {
redirect(loginUrl)
}
// This will activate the closest `error.js` Error Boundary
throw new Error('Failed to fetch data')
}
Expand All @@ -44,6 +51,9 @@ export async function fetchLahetykset(hakuParams: LahetysHakuParams) {
})
console.log(res.status)
if (!res.ok) {
if(res.status===401) {
redirect(loginUrl)
}
// This will activate the closest `error.js` Error Boundary
throw new Error('Failed to fetch data')
}
Expand Down

0 comments on commit 8de7cc5

Please sign in to comment.