예제 #1
0
파일: Index.php 프로젝트: raframework/ra
 public function lis(Request $request, Response $response)
 {
     $serverParams = $request->getServerParams();
     $host = 'http://' . $serverParams['HTTP_HOST'];
     $resourceList = [];
     foreach (Res::$uriPatterns as $pattern => $value) {
         $resourceList[] = $host . $pattern;
     }
     $response->withStatus(200)->write(json_encode($resourceList));
 }
예제 #2
0
파일: App.php 프로젝트: raframework/ra
 private function sysHandleException(\Exception $e)
 {
     if ($e instanceof MethodNotAllowedException) {
         $this->response->withStatus(405);
         $this->response->withHeader('Allow', implode(', ', $e->getAllowedMethods()));
     } else {
         if ($e instanceof NotFoundException) {
             $this->response->withStatus(404);
         } else {
             $this->response->withStatus(500);
             trigger_error('Unhandled exception \'' . get_class($e) . '\' with message \'' . $e->getMessage() . '\'' . ' in ' . $e->getFile() . ':' . $e->getLine() . "\nStack trace:\n" . $e->getTraceAsString(), E_USER_WARNING);
         }
     }
 }
예제 #3
0
 public static function process(\Exception $e, Request $request, Response $response)
 {
     if ($e instanceof BaseException) {
         $response->withStatus($e->getHttpStatus());
         $response->write(Code::json($e->getCode(), $e->getMessage()));
     } else {
         if ($e instanceof MethodNotAllowedException) {
             $response->withStatus(405);
             $allow = implode(', ', $e->getAllowedMethods());
             $response->withHeader('Allow', $allow);
             $response->write(Code::json(Code::METHOD_NOT_ALLOWED, 'allow: ' . $allow));
         } else {
             if ($e instanceof NotFoundException) {
                 $response->withStatus(404);
                 $response->write(Code::json(Code::RESOURCE_NOT_FOUND));
             } else {
                 if ($e instanceof UnsupportedMediaType) {
                     $response->withStatus(415);
                     $response->write(Code::json(Code::UNSUPPORTED_MEDIA_TYPE, $e->getMessage()));
                 } else {
                     if ($e instanceof BadBodyException) {
                         $response->withStatus(400);
                         $response->write(Code::json(Code::BAD_BODY, $e->getMessage()));
                     } else {
                         if ($e instanceof \PDOException) {
                             $response->withStatus(502);
                             $response->write(Code::json(Code::DATABASE_ERROR));
                             trigger_error(Str::exceptionToString($e), E_USER_WARNING);
                         } else {
                             if ($e instanceof \RedisException) {
                                 $response->withStatus(502);
                                 $response->write(Code::json(Code::CACHE_ERROR));
                                 trigger_error(Str::exceptionToString($e), E_USER_WARNING);
                             } else {
                                 $response->withStatus(500);
                                 $response->write(Code::json(Code::INTERNAL_SERVER_ERROR));
                                 trigger_error(Str::exceptionToString($e), E_USER_WARNING);
                             }
                         }
                     }
                 }
             }
         }
     }
 }