Rocketseat / adonis-bull

The easiest way to start using an asynchronous job queue with AdonisJS. Ready for Adonis v5 ⚡️
MIT License
310 stars 57 forks source link

No context in bull exceptions handler like in default one. #102

Open n4an opened 2 years ago

n4an commented 2 years ago

No context in bull exceptions handler like in default one.

Add information about your environment

Additional context

import Logger from '@ioc:Adonis/Core/Logger'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import HttpExceptionHandler from '@ioc:Adonis/Core/HttpExceptionHandler'

Default  Adonis handler:

export default class ExceptionHandler extends HttpExceptionHandler {

  public async handle(error: any, ctx: HttpContextContract) {   // <----------- ctx
    /**
     * Forward rest of the exceptions to the parent class
     */
    return super.handle(error, ctx)
  }
}

Bull handler

import { LoggerContract } from '@ioc:Adonis/Core/Logger'
import { Job } from 'bullmq'

/**
 * Bull exception handler serves as the base exception handler
 * to handle all exceptions occured during the BULL queue execution
 * lifecycle and makes appropriate response for them.
 */
export abstract class BullExceptionHandler {
  constructor(protected logger: LoggerContract) {}

  public async handle(error: any, job: Job) {  // <------- no ctx
    if (typeof error.handle === 'function') {
      return error.handle(error, job)
    }
    this.logger.error(error.message)
  }
}