dingo / dingo/api-docs

Error response shouldn't use return

Open
#26 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
19
Forks
21
PR merge metrics
No merged PRs in 30d

Description

In [Wiki: Responding With An Error](https://github.com/dingo/api/wiki/Responses#responding-with-an-error) it states:

```
return $this->response->errorUnauthorized();
```

However, all the method does is throws an error. The method itself has no return statement. Isn't the `return` redundant?

Consider the following controller method as example. If a return is added to the errorResponse, it does nothing except adds a warning to the IDE because there's a conflict between `return void` and the declared return type. (Adding `|void` to `@return` causes a warning too.)
```
/**
* Display the specified resource.
*
* @param \App\Letter $letter
* @return \Dingo\Api\Http\Response
*/
public function show(Letter $letter)
{
/** @var User $user */
$user = $this->auth->user();
if( $user->cannot('view', $letter) ) {
$this->response->errorUnauthorized();
}

return $this->response->item($letter, new LetterTransformer);
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.