From 5ed9405fced7562b512be1035e3f3548b4626968 Mon Sep 17 00:00:00 2001 From: Neil Guo Date: Thu, 1 Sep 2022 22:45:20 +0800 Subject: [PATCH] fix: add status on API --- src/store/index.js | 3 +++ src/views/Restaurants.vue | 7 +++++-- src/views/RestaurantsFeeds.vue | 3 +++ src/views/SignIn.vue | 4 +--- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index 7c7ba1e..5fb5d75 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -38,6 +38,9 @@ export default new Vuex.Store({ async fetchCurrentUser ({ commit }) { try { const { data } = await usersAPI.getCurrentUser() + if (data.status === 'error') { + throw new Error(data.message) + } const { id, name, email, image, isAdmin } = data diff --git a/src/views/Restaurants.vue b/src/views/Restaurants.vue index dd05a91..d377ef0 100644 --- a/src/views/Restaurants.vue +++ b/src/views/Restaurants.vue @@ -74,10 +74,13 @@ export default { async fetchRestaurants ({ queryPage, queryCategoryId }) { try { this.isLoading = true - const response = await restaurantsAPI.getRestaurants({ + const { data } = await restaurantsAPI.getRestaurants({ page: queryPage, categoryId: queryCategoryId }) + if (data.status === 'error') { + throw new Error(data.message) + } const { restaurants, @@ -87,7 +90,7 @@ export default { totalPage, prev, next - } = response.data + } = data this.restaurants = restaurants this.categories = categories diff --git a/src/views/RestaurantsFeeds.vue b/src/views/RestaurantsFeeds.vue index cfe2d31..8fd74e7 100644 --- a/src/views/RestaurantsFeeds.vue +++ b/src/views/RestaurantsFeeds.vue @@ -54,6 +54,9 @@ export default { try { this.isLoading = true const { data } = await restaurantsAPI.getFeeds() + if (data.status === 'error') { + throw new Error(data.message) + } const { restaurants, comments } = data this.restaurants = restaurants diff --git a/src/views/SignIn.vue b/src/views/SignIn.vue index 84d023c..232f86e 100644 --- a/src/views/SignIn.vue +++ b/src/views/SignIn.vue @@ -86,13 +86,11 @@ export default { this.isProcessing = true - const response = await authorizationAPI.signIn({ + const { data } = await authorizationAPI.signIn({ email: this.email, password: this.password }) - const { data } = response - if (data.status === 'error') { throw new Error(data.message) }