Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_getExceptionHandlerNamespace () {
const exceptionHandlerFile = resolver.forDir('exceptions').getPath('Handler.js')
try {
fs.accessSync(exceptionHandlerFile, fs.constants.R_OK)
return resolver.forDir('exceptions').translate('Handler')
} catch (error) {
return 'Adonis/Exceptions/BaseExceptionHandler'
}
}
_getExceptionHandlerNamespace () {
const exceptionHandlerFile = resolver.forDir('exceptions').getPath('Handler.js')
try {
fs.accessSync(exceptionHandlerFile, fs.constants.R_OK)
return resolver.forDir('exceptions').translate('Handler')
} catch (error) {
return 'Adonis/Exceptions/BaseExceptionHandler'
}
}
async _routeHandler (ctx, next, params) {
const { method } = resolver.forDir('httpControllers').resolveFunc(params[0])
const returnValue = await method(ctx)
this._safelySetResponse(ctx.response, returnValue)
await next()
}
getHandler (name, ignoreWildcard = false) {
const binding = this._bindings[name]
let handler
/**
* Give priority to binding when it exists,
* then look for inline handler and finally
* fallback to wildcard if required
*/
if (binding) {
const bindingInstance = resolver.forDir('exceptionHandlers').resolve(binding)
if (typeof (bindingInstance.handle) === 'function') {
handler = bindingInstance.handle.bind(bindingInstance)
}
}
/**
* If handler was not resolved from the binding
* then look for it inside handlers object.
*/
handler = handler || this._handlers[name]
/**
* If ignoreWildcard is false and there is no
* handler, return the wildcard handler
*/
if (!handler && !ignoreWildcard) {
_resolveListener (listener) {
const { method } = resolver.forDir('listeners').resolveFunc(listener)
if (typeof (listener) === 'string') {
this._namespacedListeners[listener] = method
}
return method
}
async handle (ctx, next, validator) {
validator = validator instanceof Array === true ? validator[0] : validator
if (!validator) {
throw new Error('Cannot validate request without a validator. Make sure to call Route.validator(\'validatorPath\')')
}
const validatorInstance = resolver.forDir('validators').resolve(validator)
/**
* Set request ctx on the validator
*/
validatorInstance.ctx = ctx
/**
* Sanitize request data if there are sanitization rules
*/
this._sanitizeData(ctx.request, validatorInstance)
/**
* Validate the request. This method should handle the request
* response, since the middleware chain has been stopped.
*
* If this method doesn't handles the response, then a generic