Skip to content

[L8] Throwing an Error from Adapter hook renders as 500 http code #566

@ProteanCode

Description

@ProteanCode

Laravel Framework 8.11.2
PHP: 7.4 fpm + nginx on top of that
Library version (according to composer.lock): v3.0.1

// Created inside the adapter
protected function creating(User $user, ResourceObject $resource): void
{
    $error = Error::fromArray([
        'title'     => 'The language you want to use is not active',
        'status'    => Response::HTTP_UNPROCESSABLE_ENTITY,
    ]);

    throw new JsonApiException($error);
}

I have followed installation steps about the exception handler so that's not it

The log content:
[2020-10-26 01:19:02] local.ERROR: JSON API error {"exception":"[object] (CloudCreativity\\LaravelJsonApi\\Exceptions\\JsonApiException(code: 0): JSON API error at /var/www/html/vendor/cloudcreativity/laravel-json-api/src/Exceptions/JsonApiException.php:51)

The handler part:

public function render($request, Throwable $e)
{
    if ($this->isJsonApi($request, $e)) {
        // It goes there
        return $this->renderJsonApi($request, $e);
    }

    return parent::render($request, $e);
}

I expected to see a 422 response, but it became somehow overshadowed by a 500 one

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions