Inconsistencies in the class Nng\Nnrestapi\Mvc\Response
Issue #6
resolved
I noticed that calling Response::error doesn’t render a response body correctly. After looking at the class, we can see the following code:
/**
* Einen Fehler ausgeben
*
* @return void
*/
public function error( $statusCode, $message = '' ) {
return $this->setStatus($statusCode)->setMessage($message)->render();
return [
'status' =>$statusCode,
'error' =>$message
];
}
With two return statements. That doesn’t make any sense and the response is incorrect.
I would suggest the following fix:
/**
* Einen Fehler ausgeben
*
* @return void
*/
public function error( $statusCode, $message = '' ) {
return $this->setStatus($statusCode)->setMessage($message)->render(
[
'status' =>$statusCode,
'error' =>$message
]);
}
Which is like any other methods do in this class. BTW I’d also suggest to rename this method to something more generic because it’s actually not related to errors as I could also set a 200 status in there.
Note: there’s the same issue with the method Response::unauthorized
Comments (3)
-
-
reporter Nice, thank you
-
- changed status to resolved
Fixed and pushed in DEV branch
- Log in to comment
Totally correct
Will be in the next release!