Custom Exceptions in AdonisJS
AdonisJS provides streamlined ways to raise exceptions in your controller or service code, and raise them in a controlled way to the caller. To create a custom exception - adonis make:exception RecordNotFoundException This will create - √ create app\Exceptions\RecordNotFoundException.js Edit the exception to introduce your own errors. "use strict"; const { LogicalException } = require("@adonisjs/generic-exceptions"); class RecordNotFoundException extends LogicalException { /** * Handle this exception by itself */ handle(error, { response }) { return response.status(404).json({ error: "Record is not found. Check other universes.", }); } } module.exports = RecordNotFoundException; We are trying to raise a 404 with a specific exception message in the above code block. ...