8000 Laravel exceptions are converted to internal server errors · Issue #570 · cloudcreativity/laravel-json-api · GitHub
[go: up one dir, main page]

Skip to content

Laravel exceptions are converted to internal server errors #570

@zarlin

Description

@zarlin

I have some logic which checks the database state, and under some conditions I want to throw an exception of a suitable type.

For example: I want to return an error 400 Bad Request to the user with a message about what is wrong.

The docs state:

This package automatically handles converting common Laravel exceptions to these error objects, for example HTTP exceptions and validation exceptions.

So I throw a BadRequestException, passing my message as a parameter:

use Symfony\Component\HttpFoundation\Exception\BadRequestException;

/**/

throw new BadRequestException("message");

However, client-side I receive:

{
	"errors": [
		{
			"status": "500",
			"title": "Internal Server Error"
		}
	]
}

Which is the wrong status, and my error message is not included.

Why does this happen?

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

      0