Commit cebb584e authored by Tobinsk's avatar Tobinsk
Browse files

Merge branch '33-400-error-handling' into 'master'

Resolve "400 error handling"

Closes #33

See merge request !29
parents 80dcfecb bf8b46de
Pipeline #6496 passed with stages
in 5 minutes and 27 seconds
......@@ -4,6 +4,6 @@ VUE_APP_KEYCLOAK_REALM="HistHub"
VUE_APP_KEYCLOAK_URL="https://iam.nubes.dodis.ch/auth"
VUE_APP_TEST_USER="test"
# please use a valid provider. Otherwise the matching won't work
VUE_APP_TEST_PROVIDER="gnd"
VUE_APP_TEST_PROVIDER="bsg"
# tbd
VUE_APP_TEST_ROLES="user"
......@@ -188,7 +188,13 @@ const concordance: Module<ConcordanceState, any> = {
params.push(`from=${pagination.from}`);
params.push(`size=${pagination.size}`);
const data = await fetch(`${api}/v3/concordances/search?${params.join('&')}`).
then(d => d.json()).catch((error) => {
then(r => {
if (r.status >= 200 && r.status <= 299) {
return r.json();
} else {
throw Error(r.statusText);
}
}).catch((error) => {
const metagridError: MetagridError = {
title: "Network error",
message: 'Can\'t fetch list of concordances from server.',
......@@ -220,7 +226,13 @@ const concordance: Module<ConcordanceState, any> = {
*/
async [Actions.DESTROY]({commit}, id: string) {
await fetch(`${api}/v3/concordances/${id}`,
{method: 'DELETE' }).catch((err) => {
{method: 'DELETE' }).then(r => {
if (r.status >= 200 && r.status <= 299) {
return r.json();
} else {
throw Error(r.statusText);
}
}).catch((err) => {
const metagridError: MetagridError = {
title: "Network error",
message: 'Can\'t delete concordances.',
......@@ -247,8 +259,13 @@ const concordance: Module<ConcordanceState, any> = {
'Content-Type': 'application/json'
},
})
.then(r => r.json())
.catch((err) => {
.then(r => {
if (r.status >= 200 && r.status <= 299) {
return r.json();
} else {
throw Error(r.statusText);
}
}).catch((err) => {
const metagridError: MetagridError = {
title: "Network error",
message: 'Can\'t merge concordances.',
......@@ -269,8 +286,13 @@ const concordance: Module<ConcordanceState, any> = {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
}).then(r => r.json())
.catch((err) => {
}).then(r => {
if (r.status >= 200 && r.status <= 299) {
return r.json();
} else {
throw Error(r.statusText);
}
}).catch((err) => {
const metagridError: MetagridError = {
title: "Network error",
message: 'Can\'t update concordance.',
......
......@@ -114,8 +114,13 @@ const match: Module<MatchState, any> = {
async [Actions.LIST]({commit}, pagination: Pagination) {
commit(Mutations.START_LOAD);
const m = await fetch(`${api}/v3/matches`)
.then(r => r.json())
.catch((err) => {
.then(r => {
if (r.status >= 200 && r.status <= 299) {
return r.json();
} else {
throw Error(r.statusText);
}
}).catch((err) => {
const metagridError: MetagridError = {
title: "Network error",
message: 'Can\'t fetch list of matchings.',
......@@ -146,8 +151,13 @@ const match: Module<MatchState, any> = {
let match = state.list.find((m: any) => m.id === id);
if(typeof match === 'undefined') {
match = await fetch(`${api}/v3/matches/${id}`)
.then(r => r.json())
.catch((err) => {
.then(r => {
if (r.status >= 200 && r.status <= 299) {
return r.json();
} else {
throw Error(r.statusText);
}
}).catch((err) => {
const metagridError: MetagridError = {
title: "Network error",
message: 'Can\'t fetch matching from server.',
......@@ -171,8 +181,13 @@ const match: Module<MatchState, any> = {
'Content-Type': 'application/json'
},
})
.then(r => r.json())
.catch((err) => {
.then(r => {
if (r.status >= 200 && r.status <= 299) {
return r.json();
} else {
throw Error(r.statusText);
}
}).catch((err) => {
const metagridError: MetagridError = {
title: "Network error",
message: 'Can\'t save matching.',
......
import {api, Pagination, MatchProposal, Match, MetagridError} from '@/store';
import {api, MatchProposal, Match, MetagridError} from '@/store';
import { Module} from "vuex"
import {Actions, Getters, Mutations} from '@/store/proposal/type';
import {ErrorType} from '@/store/error';
......@@ -114,7 +114,13 @@ const proposal: Module<ProposalState, any> = {
params.push(`from=${pagination.from}`);
params.push(`size=${pagination.size}`);
const proposals = await fetch(`${api}/v3/matches/${state.id}/proposals?${params.join("&")}`)
.then(r => r.json())
.then(r => {
if (r.status >= 200 && r.status <= 299) {
return r.json();
} else {
throw Error(r.statusText);
}
})
.catch((err) => {
const metagridError: MetagridError = {
title: "Network error",
......@@ -148,7 +154,13 @@ const proposal: Module<ProposalState, any> = {
'Content-Type': 'application/json'
},
})
.then(r => r.json())
.then(r => {
if (r.status >= 200 && r.status <= 299) {
return r.json();
} else {
throw Error(r.statusText);
}
})
.catch((err) => {
const metagridError: MetagridError = {
title: "Network error",
......
......@@ -34,8 +34,13 @@ const provider: Module<ProviderState, any> = {
*/
async [Actions.LIST]({commit, rootState}) {
const data = await fetch(`${api}/v3/providers`).
then(d => d.json())
.catch((err) => {
then(r => {
if (r.status >= 200 && r.status <= 299) {
return r.json();
} else {
throw Error(r.statusText);
}
}).catch((err) => {
const metagridError: MetagridError = {
title: "Network error",
message: 'Can\'t fetch list of provider. Network error',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment