/**
  * @inheritdoc
  */
 public function register()
 {
     $this->app->error(function (Exception $exception) {
         ErrorHandler::logException($exception);
         return ErrorHandler::errorInternalError($exception->getMessage(), (new \ReflectionClass($exception))->getShortName());
     });
     // always return json error response for 404s
     $this->app->missing(function () {
         $requestUri = Request::getRequestUri();
         return ErrorHandler::errorNotFound("The request URI '{$requestUri}' was not found");
     });
     $this->app->error(function (EntityNotFound $exception) {
         // todo - evaluate the need for logging 'not found' exceptions
         ErrorHandler::logException($exception);
         return ErrorHandler::errorNotFound($exception->getMessage());
     });
     $this->app->error(function (EntityAlreadyExists $exception) {
         ErrorHandler::logException($exception);
         return ErrorHandler::errorConflict($exception->getMessage());
     });
     $this->app->error(function (InvalidEntity $exception) {
         ErrorHandler::logException($exception);
         return ErrorHandler::errorWrongArgs($exception->getMessage());
     });
 }
Example #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  string $id
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function update($id)
 {
     if (Input::isJson()) {
         $data = Input::all();
     } elseif ($this->requestContainsYaml()) {
         $data = Yaml::parse(Input::getContent());
     } else {
         return ErrorHandler::errorUnsupportedMediaType("Content-Type must be 'application/json' or 'application/yaml");
     }
     $updatedResource = $this->service->update($id, $data);
     return $this->respondWithItem($updatedResource, $this->transformer);
 }