Преглед изворни кода

Ref #12 Updated the format of response when exists an error.

Maximiliano Schvindt пре 6 година
родитељ
комит
3038a3a6e7

+ 2 - 0
src/Swagger/Client/Base/Services.php

@@ -209,6 +209,7 @@ class Services extends ApiServices
                                 $content = "No se pudo obtener el acceso cargado. Verifique por sistema si la carga se realizo correctamente.";
                             }
                         } else {
+                            $codeResponse = 409;
                             $content = "El externalId ya existe y pertenece al cliente " . $name . ".";
                         }
                     } else {
@@ -268,6 +269,7 @@ class Services extends ApiServices
                                 $content = "No se pudo obtener el acceso cargado. Verifique por sistema si la carga se realizo correctamente.";
                             }
                         } else {
+                            $codeResponse = 409;
                             $content = "El externalId ya existe y pertenece al cliente " . $name . ".";
                         }
                     } else {

+ 2 - 0
src/Swagger/Client/Cablemodem/Services.php

@@ -403,6 +403,7 @@ class Services extends ApiServices
                                     }
                                 }
                             } else {
+                                $codeResponse = 409;
                                 $content = "La MAC ya existe y pertenece al cablemodem " . $name . ".";
                             }
                         }
@@ -500,6 +501,7 @@ class Services extends ApiServices
                                     }
                                 }
                             } else {
+                                $codeResponse = 409;
                                 $content = "La MAC ya existe y pertenece al cablemodem " . $name . ".";
                             }
                         }

+ 2 - 0
src/Swagger/Client/FTTH/Services.php

@@ -846,6 +846,7 @@ class Services extends ApiServices
                                     }
                                 }
                             } else {
+                                $codeResponse = 409;
                                 $content = "El pon serial number ya existe y pertenece a la onu " . $name . ".";
                             }
                         }
@@ -998,6 +999,7 @@ class Services extends ApiServices
                                     }
                                 }
                             } else {
+                                $codeResponse = 409;
                                 $content = "El externalId ya existe y pertenece al cliente " . $name . ".";
                             }
                         }

+ 4 - 2
src/Utils.php

@@ -76,8 +76,10 @@ class Utils
     public function returnJSON($content, $codeResponse = 400) {
 
         json_decode($content,true);
-        if(json_last_error() != JSON_ERROR_NONE) 
-            $content = json_encode(['message' => $content]);
+        if(json_last_error() != JSON_ERROR_NONE) { // error - https://cloud.google.com/storage/docs/json_api/v1/status-codes
+            $return = array('error' => array('code' => $codeResponse, 'message' => $content));
+            $content = json_encode($return);
+        } 
 
         
         return new Response($content, $codeResponse, ['content-type' => 'application/json']);