/**
  * Create error response from exception
  * @param \Exception $e
  * @return \Drahak\Restful\IResource
  */
 protected function createErrorResource(\Exception $e)
 {
     $resource = $this->resourceFactory->create(array('code' => $e->getCode(), 'status' => 'error', 'message' => $e->getMessage()));
     if (isset($e->errors) && $e->errors) {
         $resource->errors = $e->errors;
     }
     return $resource;
 }
Exemple #2
0
 /**
  * Create error response from exception
  * @param \Exception|\Throwable $e
  * @return \Drahak\Restful\IResource
  */
 protected function createErrorResource($e)
 {
     if ($e instanceof \Exception || $e instanceof \Throwable) {
         $resource = $this->resourceFactory->create(array('code' => $e->getCode(), 'status' => 'error', 'message' => $e->getMessage()));
     } else {
         $resource = $this->resourceFactory->create(array('code' => 500, 'status' => 'error', 'message' => (string) $e));
     }
     if (isset($e->errors) && $e->errors) {
         $resource->errors = $e->errors;
     }
     return $resource;
 }