I am building a json api. Formats are managed nicely via the routing.yml configuration file:
user_info:
url: /users/:user_id
class: sfRequestRoute
param: { module: user, action: details, sf_format: json }
requirements:
user_id: \d+
sf_method: [GET]
Now I would like to make sure that any request that is sent to my app will return a result in json format (example: "/dummy" should return an error in json). I am getting on track with the following default route at the end of the same file:
default:
url: /*
param: { sf_format: json }
When I route to an inexisting page or module, this renders correctly a json... Error! The html page generated was a 404, now with this routing I get a 500 (server error). How can I keep a similar behaviour as the one I had in the default html page, just changing the rendering into a json output?
EDIT - following 1Ed instructions
So I edited my factories.yml, created a default module in my api project, there in my default actions added the executeError404 function mentioned below... Then I Set up the corresponding Error404Success.php page...
For some reason, I still need the routes, which I modified to avoid the :module and :action keywords:
default_index:
url: /:a
default:
url: /:a/:b/*
And here there I am ! My 404 page comes in json format for the whole api :) Thanks a lot !