From 97b3d0fee488fb0bd1953c6525d8830bfd12fdc1 Mon Sep 17 00:00:00 2001
From: Bertrand PINEL <bpinel@ippon.fr>
Date: Wed, 11 Nov 2020 18:06:01 +0100
Subject: [PATCH] Take into account Colin and Nicolas remark from Blog post

---
 app/services/mapbox-ws.js | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/app/services/mapbox-ws.js b/app/services/mapbox-ws.js
index 94867d5..a9fc8e6 100644
--- a/app/services/mapbox-ws.js
+++ b/app/services/mapbox-ws.js
@@ -41,11 +41,11 @@ export default class MapboxWsService extends Service {
         "Access-Control-Allow-Origin": "*"
     }
     });
-    if (response.status === 200 && response.data.code === 'Ok') {
-        return { coords: response.data.routes[0].geometry.coordinates, dist: response.data.routes[0].distance };
-    } else {
-        return { coords: [], dist: 0};
-    }   
+    if (response.status !== 200 && response.data.code !== 'Ok') {
+      return { coords: [], dist: 0};
+    }  
+    return { coords: response.data.routes[0].geometry.coordinates, dist: response.data.routes[0].distance };
+
   }
 
   async optimize(profile, coord1, coord2) {
@@ -61,11 +61,10 @@ export default class MapboxWsService extends Service {
         "Access-Control-Allow-Origin": "*"
     }
     });
-    if (response.status === 200 && response.data.code === 'Ok') {
-        return response.data.trips[0].geometry.coordinates;
-    } else {
-        return [];
+    if (response.status !== 200 || response.data.code !== 'Ok') {
+      return [];   
     }
+    return response.data.trips[0].geometry.coordinates;
   }
   
   headers() {
-- 
GitLab