RoboSats / robosats

A simple and private bitcoin exchange
https://learn.robosats.com
GNU Affero General Public License v3.0
724 stars 142 forks source link

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

Open jerryfletcher21 opened 6 months ago

jerryfletcher21 commented 6 months ago

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.

Reckless-Satoshi commented 6 months ago

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.