Closed claudesortwell closed 2 years ago
There was an issue with the polls app in which the exception handler itself was raising exception. Hence the server returned a generic error. I have fixed that error here https://github.com/adonisjs-community/polls-app/commit/553f25d6decfe88cf72ada4af33c58b48e41fc80 and now the poll app does render status pages.
Are you testing the same on local? If yes, then status pages are only rendered when the NODE_ENV=production
. However, there is a flag to force status page to render in development too. https://docs.adonisjs.com/guides/exception-handling#status-pages
I'll provide a sample repo tomorrow for you. Ive tried adding the force status flag, no luck. I think it might have to do with starting adonis with the api template then adding front end.
Ohh is it that you are using the API template? If yes, then shouldn't you expect your API server to always return JSON and not HTML?
Yeah ive used the API Template then added Views. So im guessing there is no way to make it return html errors after adding views. I've added a catch all route for 404, in the view side
Yes, as of now the status pages are not for the API template. However, I am still curious to know why you want to return HTML from an API server?
Yeah makes sense. It's kinda of a hybrid application. So API for customer's SPA then we have an admin portal built with the adonis views.
You can probably close this now, as I understand your reasoning for not adding views in an API template. Maybe adding some middleware error catching or a custom handler will work for hybrid applications.
You can still manage it, if your API is nested within some prefix like /api
. Then you can use the changes implemented in this PR https://github.com/adonisjs/http-server/pull/51/files#diff-02b5b8ba60024cffe8cebc1ff41db79cd8baab6e1fb61101ffbcd2eff3e04ff3R591
Lemme know if that is the case and you need any help with implementation
What is happening?
Adonis is not rendering error pages defined in statusPages in handler.ts, this also does not working in dev using the optional boolean. A prime example is the Adonis Poll example, but even in my private repo, I have the same problem.
Package version
Node.js and npm version
v14.16.1, Yarn 3.1.1
Sample Code (to reproduce the issue)
BONUS (a sample repo to reproduce the issue)
Polls App Example route not founds not working https://polls.adonisjs.dev/qwfqwfeqf. According to the repos handler.ts, it should render the route not found edge page but the link is rendering the default error: