Hello everyone, Odoo beginner here!
My controller is working properly, but i want to be able to return different responses than 200 with specific error messages.
I have found this controller parameter "handle_params_access_error" (new in odoo 17) in the Odoo documentation but i cannot figure out how to use it.
from odoo import http
from werkzeug.exceptions import UnprocessableEntity
# from werkzeug.wrappers.response import Response
from odoo.http import Response
class Api_Name(http.Controller):
@http.route('/route_name', auth='user', type = "json", csrf=False, method=['POST'])
def index(self,**kw):
if len(kw["data"]) != 2:
response = UnprocessableEntity("Invalid length")
raise response
return response
[...]
return response
When testing the above code with Postman, i receive a status 200 with an error message : "message": "422 Unprocessable Entity: Invalid length".
I cannot manage to receive a status 422 instead.
Any help would be greatly appreciated, thank you !