From 9fbdd98bc6d5ffcad9b8793f12be03db58aa3e6e Mon Sep 17 00:00:00 2001 From: tim Date: Mon, 5 Jul 2021 04:37:28 +0200 Subject: [PATCH] Add error handling --- src/services/PerudoApi.ts | 5 ++++- src/views/Home.vue | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/services/PerudoApi.ts b/src/services/PerudoApi.ts index c8737be..dd1297a 100644 --- a/src/services/PerudoApi.ts +++ b/src/services/PerudoApi.ts @@ -41,8 +41,11 @@ export default class PerudoApi { }); } - private get(url: string, getParameters?: Record) { + private get(url: string, getParameters?: Record): AxiosPromise { return axios.get(url).then((response: AxiosResponse) => { + if (response?.data?.errors?.length > 0) { + throw response.data.errors?.join(); + } return response; }) } diff --git a/src/views/Home.vue b/src/views/Home.vue index 5effb35..f6d7c72 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -1,5 +1,9 @@