Browse Source

restore global error management

Olivier Massot 10 tháng trước cách đây
mục cha
commit
c74c0844e0
3 tập tin đã thay đổi với 19 bổ sung23 xóa
  1. 5 0
      plugins/error.ts
  2. 0 5
      plugins/error.ts.off
  3. 14 18
      services/data/entityManager.ts

+ 5 - 0
plugins/error.ts

@@ -0,0 +1,5 @@
+export default defineNuxtPlugin((nuxtApp) => {
+  nuxtApp.vueApp.config.errorHandler = (error, _) => {
+    console.error(error)
+  }
+})

+ 0 - 5
plugins/error.ts.off

@@ -1,5 +0,0 @@
-export default defineNuxtPlugin((nuxtApp) => {
-    nuxtApp.vueApp.config.errorHandler = (error, context) => {
-        console.log(error)
-    }
-})

+ 14 - 18
services/data/entityManager.ts

@@ -178,28 +178,24 @@ class EntityManager {
     id: number,
     forceRefresh: boolean = false,
   ): Promise<ApiResource> {
-    try {
-      // If the model instance is already in the store and forceRefresh is false, return the object in store
-      if (!forceRefresh) {
-        // TODO: est-ce qu'il y a vraiment des situations où on appellera cette méthode sans le forceRefresh?
-        const item = this.find(model, id)
-        if (item && typeof item !== 'undefined') {
-          return item
-        }
+    // If the model instance is already in the store and forceRefresh is false, return the object in store
+    if (!forceRefresh) {
+      // TODO: est-ce qu'il y a vraiment des situations où on appellera cette méthode sans le forceRefresh?
+      const item = this.find(model, id)
+      if (item && typeof item !== 'undefined') {
+        return item
       }
+    }
 
-      // Else, get the object from the API
-      const url = UrlUtils.join('api', model.entity, String(id))
-      const response = await this.apiRequestService.get(url)
+    // Else, get the object from the API
+    const url = UrlUtils.join('api', model.entity, String(id))
+    const response = await this.apiRequestService.get(url)
 
-      // deserialize the response
-      const attributes = HydraNormalizer.denormalize(response, model)
-        .data as object
+    // deserialize the response
+    const attributes = HydraNormalizer.denormalize(response, model)
+      .data as object
 
-      return this.newInstance(model, attributes)
-    } catch (e) {
-      console.error(e)
-    }
+    return this.newInstance(model, attributes)
   }
 
   /**