Skip to content

Inertia - Status code on exception #4563

Answered by Julien-R44
Xstoudi asked this question in Help
Discussion options

You must be logged in to vote

If you're using the inertia starter-kit then it's handled automatically for you in the Exception Handler. See there : https://github.com/adonisjs/inertia-starter-kit/blob/main/app/exceptions/handler.ts#L24

If you throw an exception with a 404 status code, your error page will be rendered with Inertia. For example, this is the case with Lucid's findxxOrFail methods:

export default class UsersController {
  async index({ inertia, response }: HttpContext) {
    const user = await User.findOrFail(1212121);

    // ...
  }
}

If the user is not found, then :

  • The exception E_ROW_NOT_FOUND will be thrown. This same E_ROW_NOT_FOUND exception uses a status code 404 as seen in the linked code.
  • We e…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by RomainLanz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants