[ActiveJob] Discard job not based on exception type


I have seem Rails Guides about feature request and Im posting this idea/issue here, in case of someone is disposal to implement it, or if people enough think is a good idea maybe I can do, is a simple problem but seems to not have a ready-solution.

Basically, in the active job we have the discard_on method, which accepts a error type or a block(created to report the error somewhere else).

My issue is that I have 2 different errors that are the same type, but the error arguments and message are different, the error is ActiveResource::ClientError, I want basically discard this error when status is 400, and not discard when status is 403.

I did not found any solution for that, someone has any idea of how solve this? The block of discard_on did not seems to return an true/false, that would be the ideal solution, if return true then it is discarded, if returns false, not discard.

You can use rescue_from instead of discard_on: