added basic error handling
This commit is contained in:
parent
a7d4edb4ad
commit
b0ac2a4412
@ -1 +1 @@
|
|||||||
VITE_EO_SERVICES_URL=http://localhost:9000
|
VITE_EO_SERVICES_URL=http://localhost:3000
|
||||||
|
|||||||
@ -1,31 +1,42 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
|
||||||
import ContactTable from './components/ContactTable.vue'
|
import ContactTable from './components/ContactTable.vue'
|
||||||
import ContactsSummary from './components/ContactsSummary.vue';
|
import ContactsSummary from './components/ContactsSummary.vue';
|
||||||
|
import Error from './components/Error.vue';
|
||||||
|
|
||||||
const referenceId = ref('')
|
const referenceId = ref('')
|
||||||
const contactData = ref(null)
|
const contactData = ref(null)
|
||||||
|
const errorMessage = ref(null)
|
||||||
|
|
||||||
function onInput(e) {
|
function onInput(e) {
|
||||||
referenceId.value = e.target.value
|
referenceId.value = e.target.value
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchData() {
|
function fetchData() {
|
||||||
|
//clear errors
|
||||||
|
errorMessage.value = null
|
||||||
contactData.value = null
|
contactData.value = null
|
||||||
const res = await fetch(`${import.meta.env.VITE_EO_SERVICES_URL}/unified-data-gateway?referenceId=${ referenceId.value }`, {
|
fetch(`${import.meta.env.VITE_EO_SERVICES_URL}/unified-data-gateway?referenceId=${ referenceId.value }`, {
|
||||||
credentials: "include" // fetch won't send cookies unless you set credentials
|
credentials: "include" // fetch won't send cookies unless you set credentials
|
||||||
})
|
}).then (async response => {
|
||||||
contactData.value = await res.json()
|
const data = await response.json();
|
||||||
console.log(contactData.value)
|
|
||||||
|
// check for error response
|
||||||
|
if (!response.ok) {
|
||||||
|
// get error message from body or default to response statusText
|
||||||
|
const error = data || response.statusText;
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
contactData.value = await data;
|
||||||
|
}).catch(error => {
|
||||||
|
errorMessage.value = error;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<!-- <header>
|
|
||||||
<h1>Message Tracking Time</h1>
|
|
||||||
</header> -->
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label for="referenceId">Reference ID: </label>
|
<label for="referenceId">Reference ID: </label>
|
||||||
<input id="referenceId" :value="referenceId" @input="onInput" placeholder="enter Reference ID here" />
|
<input id="referenceId" :value="referenceId" @input="onInput" placeholder="enter Reference ID here" />
|
||||||
@ -35,8 +46,11 @@ async function fetchData() {
|
|||||||
<ContactsSummary v-if="contactData" :summary="contactData.data.summary" />
|
<ContactsSummary v-if="contactData" :summary="contactData.data.summary" />
|
||||||
<div v-else>No Contacts Found</div>
|
<div v-else>No Contacts Found</div>
|
||||||
<ContactTable v-if="contactData" :tableData="contactData.data.findContactsCompletedBetween.edges" />
|
<ContactTable v-if="contactData" :tableData="contactData.data.findContactsCompletedBetween.edges" />
|
||||||
|
<Error v-if="errorMessage" :errorMessage="errorMessage" />
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<style scoped></style>
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
||||||
|
|||||||
12
src/components/Error.vue
Normal file
12
src/components/Error.vue
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<script setup>
|
||||||
|
|
||||||
|
// eslint-disable-next-line
|
||||||
|
defineProps(["errorMessage"]);
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<p v-if="errorMessage">Error: {{ errorMessage }}</p>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
</style>
|
||||||
Loading…
x
Reference in New Issue
Block a user