Skip to content

Error response shouldn't use return #26

Open
@jclee100

Description

@jclee100

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions