Explorar el Código

:recycle: using some try-catch to produce better errors

tags/0.0.3^2
j hace 3 años
padre
commit
b0894306d4

+ 15
- 10
frontend/src/services/grouping.service.js Ver fichero

@@ -9,18 +9,23 @@ import { Grouping, Profile } from '../entities/index.js'
9 9
  * @returns {array} instantiated Profile objects (see: /entites/profile)
10 10
  */
11 11
 const fetchMembershipsByProfileId = async profileId => {
12
-    const membershipsForProfileId = await db.get(`/membership/${profileId}`)
13 12
     const validGroupingInstances = []
14
-    for (let membership of membershipsForProfileId) {
15
-        const grouping = new Grouping(membership)
16
-        grouping.tags = await db.get(
17
-            `/profile/${profileId}/tags/${grouping.grouping_id}`,
18
-        )
19
-        if (grouping.isValid()) {
20
-            // Reformat incoming profile data into Profile entity
21
-            grouping.profile = new Profile(grouping.profile)
22
-            validGroupingInstances.push(grouping)
13
+    let memberships
14
+    try {
15
+        memberships = await db.get(`/membership/${profileId}`)
16
+        for (let membership of memberships) {
17
+            const grouping = new Grouping(membership)
18
+            grouping.tags = await db.get(
19
+                `/profile/${profileId}/tags/${grouping.grouping_id}`,
20
+            )
21
+            if (grouping.isValid()) {
22
+                // Reformat incoming profile data into Profile entity
23
+                grouping.profile = new Profile(grouping.profile)
24
+                validGroupingInstances.push(grouping)
25
+            }
23 26
         }
27
+    } catch (error) {
28
+        console.error(`[Grouping Service]: ${error}\ngroupings: ${memberships}`)
24 29
     }
25 30
     return validGroupingInstances
26 31
 }

+ 12
- 22
frontend/src/services/survey.service.js Ver fichero

@@ -8,12 +8,18 @@ import { db } from '../utils/db.js'
8 8
  * @returns {array} instantiated Profile objects (see: /entites/profile)
9 9
  */
10 10
 const fetchQuestions = async () => {
11
-    const questions = await db.get(`/survey/questions`)
12
-    // Add responses to match the format from the survery factory
13
-    return questions.map(q => {
14
-        q.responses = !q.responses ? [] : q.responses
15
-        return q
16
-    })
11
+    let withResponses
12
+    try {
13
+        const questions = await db.get(`/survey/questions`)
14
+        // Add responses to match the format from the survery factory
15
+        withResponses = questions.map(q => {
16
+            q.responses = !q.responses ? [] : q.responses
17
+            return q
18
+        })
19
+    } catch (error) {
20
+        console.error(`[Survey Service]: ${error}\nquestions: ${withResponses}`)
21
+    }
22
+    return withResponses
17 23
 }
18 24
 
19 25
 const updateSurveyByProfileId = async (surveyResponses, profileId) => {
@@ -32,22 +38,6 @@ const updateSurveyByProfileId = async (surveyResponses, profileId) => {
32 38
     })
33 39
 }
34 40
 
35
-// const updateSurveyByProfileId = async (surveyResponses, profileId) => {
36
-//     surveyResponses.forEach(responseKeyIdwithVal => {
37
-//         const keyId = responseKeyIdwithVal.response_key_id
38
-//         const val = responseKeyIdwithVal.val
39
-//         // PATCH
40
-//         db.patch(`/profile/${profileId}/update/${keyId}`, [
41
-//             {
42
-//                 response_id: 2,
43
-//                 profile_id: profileId,
44
-//                 response_key_id: keyId,
45
-//                 val: val,
46
-//             },
47
-//         ])
48
-//     })
49
-// }
50
-
51 41
 const scoreSurveyByProfileId = async (profileId, maxDistance = 99) => {
52 42
     const scoreSurvey = await db.get(
53 43
         `/profile/${profileId}/score?max_distance=${maxDistance}`,

+ 2
- 2
frontend/src/utils/db.js Ver fichero

@@ -34,7 +34,7 @@ class Connector {
34 34
             const jsonRes = await res.json()
35 35
             return jsonRes.data
36 36
         } catch (error) {
37
-            console.error(error)
37
+            console.error(`[API Util]: ${error}\nroute:`, endpoint)
38 38
         }
39 39
     }
40 40
     async post(endpoint, payload = {}) {
@@ -67,7 +67,7 @@ class Connector {
67 67
             console.error(error)
68 68
         }
69 69
     }
70
-    
70
+
71 71
     /** !: DEV ONLY */
72 72
     // async removeAll() { }
73 73
 }

+ 26
- 2
frontend/src/utils/index.js Ver fichero

@@ -4,8 +4,32 @@ import { SurveyFactory } from './survey.js'
4 4
 import { possible } from './lang.js'
5 5
 import { pidMixin, cardMixin } from './mixins.js'
6 6
 
7
-import config from '../../../backend/db/data-generator/config.json' assert { type: 'json' }
8
-const possibleZipcodes = config.possibleZipcodes
7
+// This will NOT work until ES2022 gets assert in browsers
8
+// import config from '../../../backend/db/data-generator/config.json' assert { type: 'json' }
9
+// TODO: Remove this when assert works in browsers
10
+const possibleZipcodes = [
11
+    '90012',
12
+    '90040',
13
+    '90058',
14
+    '90064',
15
+    '90065',
16
+    '90240',
17
+    '90274',
18
+    '90278',
19
+    '90280',
20
+    '90290',
21
+    '90291',
22
+    '90292',
23
+    '90293',
24
+    '90840',
25
+    '91001',
26
+    '91011',
27
+    '91030',
28
+    '91201',
29
+    '91399',
30
+    '91401',
31
+    '97075',
32
+]
9 33
 
10 34
 const api = new Connector('kittens')
11 35
 

Loading…
Cancelar
Guardar