Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error response shouldn't use return #26

Open
jclee100 opened this issue Apr 9, 2017 · 0 comments
Open

Error response shouldn't use return #26

jclee100 opened this issue Apr 9, 2017 · 0 comments

Comments

@jclee100
Copy link

jclee100 commented Apr 9, 2017

In Wiki: 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant