robosats icon indicating copy to clipboard operation
robosats copied to clipboard

POST api/order/ cancel returns error 400 bad_request when successful

Open jerryfletcher21 opened this issue 1 year ago • 1 comments
trafficstars

Describe the bug Other POST api/order/ action do not return error when successful, but cancel returns error 400 "bad_request": "This order has been cancelled by the maker". I think this is because when requesting an order that is canceled this is what is returned, but while doing the cancelling action is weird to be returned an error when successful. Maybe to fix, when requesting an order that is cancelled, it can be returned a json without error, something like "status": "This order has been cancelled by the maker".

in api/views.py:

        # 2) If order has been cancelled
        if order.status == Order.Status.UCA:
            return Response(
                {"bad_request": "This order has been cancelled by the maker"},
                status.HTTP_400_BAD_REQUEST,
            )
        if order.status == Order.Status.CCA:
            return Response(
                {"bad_request": "This order has been cancelled collaborativelly"},
                status.HTTP_400_BAD_REQUEST,
            )

To Reproduce Make a POST request at api/order/ with the action cancel.

Expected behavior Not to be returned an error when then cancel is successful.

jerryfletcher21 avatar Apr 25 '24 14:04 jerryfletcher21

Indeed, cancel_order action will give you the same response as a GET /order, which will be a bad request because of cancelled order. This should be improved.

Reckless-Satoshi avatar Apr 29 '24 23:04 Reckless-Satoshi