Browse Source

exception catch; print result

develop
Robin Thoni 8 years ago
parent
commit
b9e1be975c
2 changed files with 26 additions and 2 deletions
  1. 1
    1
      src/Utils/Controller/LuRoute.php
  2. 25
    1
      src/Utils/Controller/LuticateApplication.php

+ 1
- 1
src/Utils/Controller/LuRoute.php View File

@@ -146,7 +146,7 @@ class LuRoute {
146 146
             $handler = $routeInfo[1];
147 147
             $urlVars = $routeInfo[2];
148 148
             $parameters = array_merge($parameters, $urlVars);
149
-            $handler($parameters);
149
+            return $handler($parameters);
150 150
         }
151 151
     }
152 152
     

+ 25
- 1
src/Utils/Controller/LuticateApplication.php View File

@@ -8,6 +8,10 @@
8 8
 
9 9
 namespace Luticate\Utils\Controller;
10 10
 
11
+use Luticate\Utils\Business\LuBusinessException;
12
+use Luticate\Utils\Business\LuLog;
13
+use Luticate\Utils\Dbo\LuDbo;
14
+use Luticate\Utils\Dbo\LuRequestDbo;
11 15
 use Ratchet\ConnectionInterface;
12 16
 use Ratchet\MessageComponentInterface;
13 17
 use Ratchet\Http\HttpServer;
@@ -85,8 +89,28 @@ class LuticateApplication implements MessageComponentInterface
85 89
         $url = $_SERVER['REQUEST_URI'];
86 90
 
87 91
         $parameters = array_merge($_GET, $_POST);
92
+        $r = new LuRequestDbo();
93
+        $r->setVersion($this->getVersion());
88 94
 
89
-        $this->_router->dispatch($httpMethod, $url, $parameters);
95
+        try {
96
+            $result = $this->_router->dispatch($httpMethod, $url, $parameters);
97
+            $r->setData($result);
98
+            $r->setStatusCode(200);
99
+        }
100
+        catch (LuBusinessException $e)
101
+        {
102
+            LuLog::log($e);
103
+            $r->setStatusCode($e->getCode());
104
+            $r->setMessage($e->getMessage());
105
+        }
106
+        catch (\Exception $e)
107
+        {
108
+            LuLog::log($e);
109
+            $r->setStatusCode(500);
110
+            $r->setMessage("Internal Error");
111
+        }
112
+        http_response_code($r->getStatusCode());
113
+        echo $r->__toString();
90 114
     }
91 115
     
92 116
     public function runWs()

Loading…
Cancel
Save