Skip to content

Cornice doesn't throw a bad request if error list is empty #530

@SabareeshKumar

Description

@SabareeshKumar

Hi

I am writing a REST API using cornice. This is my code:

from pyramid.httpexceptions import HTTPBadRequest

@my_service.get(
    permission="my_permission",
    validators=(my_validator),
)
def my_service(request):
    # My code
    request.errors.status = HTTPBadRequest.code
    return

In the above API, I am explicitly setting the errors' status to Bad request.

But the API response status code is returned as 200.

When I add an error message into request.errors like (below), the status code is set properly.

request.errors.add('path', 'id', 'Invalid id')

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