I am using rocketpant for rest API implementation. From this doc I can see rocketpant has considered error handling in controller nicely.
However, it seems like it does not consider routing error, so if the requested url has no route defined, instead of returning json error, it render back html 404 page, which is not correct for API design.
I found the solution.
Step1: catch all unmatched routes in the last line of routing file.
Step2: define a error controller and routing method as custom error handler. throw rocketpant built in :not_found error