/** * Returns HTTP response explaining the error that caused the exception. * * @return Response */ public function returnResponse() { $response = new Response(); $response->setStatusCode(409, 'Error during FB callback'); $response->setJsonContent(['status' => 'ERROR', 'message' => $this->message]); return $response; }
/** * Returns HTTP response explaining the error that caused the exception. * * @return Response */ public function returnResponse() { $response = new Response(); $response->setStatusCode(409, 'Fb user is not valid'); $response->setJsonContent(['status' => 'ERROR', 'message' => $this->resource->getMessages()]); return $response; }
/** * Returns HTTP response explaining the error that caused the exception. * * @return Response */ public function returnResponse() { $response = new Response(); $response->setStatusCode(404, 'Resource Not Found'); $response->setJsonContent(['status' => 'ERROR', 'message' => $this->message]); return $response; }
/** * Check if the resource is saved or not and returns a response depending on this. * @param $resource * @return Response */ protected function response($resource) { // Create a response $response = new Response(); // Request method $method = $this->request->getMethod(); if ($method === "POST" || $method === "PUT") { if ($resource->save() == true) { // Change the HTTP status if ($method === "POST") { $response->setStatusCode(201, "Created"); } else { $response->setStatusCode(200, "Updated"); } $response->setJsonContent(array('status' => 'OK', 'data' => $resource)); } else { $response = new Response(); // Change the HTTP status $response->setStatusCode(409, "Conflict"); // Send errors to the client $errors = array(); foreach ($resource->getMessages() as $message) { $key = $message->getField(); if (empty($key)) { $errors[] = $message->getMessage(); } else { if (!isset($errors[$key])) { $errors[$key] = array(); } $errors[$key][] = $message->getMessage(); } } $response->setJsonContent(array('status' => 'ERROR', 'messages' => $errors)); } } else { if ($resource->delete() == true) { $response->setStatusCode(200, "Deleted"); $response->setJsonContent(array('status' => 'OK')); } else { // Change the HTTP status $response->setStatusCode(409, "Conflict"); $response->setJsonContent(array('status' => 'ERROR', 'messages' => 'Internal error while deleting')); } } return $response; }