getjerry/nest-casl

Question: How could I use CASL ForbiddenError.setDefaultMessage?

Opened this issue · 5 comments

Greetings,

Thank you so much for the work on this library.

I have one quick question that I'm unable to figure out nor to find out where it is implemented in the codebase, so that I can use CASL ForbiddenError.setDefaultMessage i.e https://casl.js.org/v5/en/api/casl-ability#forbidden-error

Could you please sched some light on this so I can have specific reason set with because?

Thanks,

-- Daniel

I am also interested in this

@ViruSzZ curious if you have been able to solve this.

@ViruSzZ curious if you have been able to solve this.

Unfortunately not.

@ViruSzZ understood thank you. I was able to do it in my own fork by replacing .can line in access.service.ts:

// return userAbilities.can(ability.action, subject(ability.subject as any, subjectInstance));
    ForbiddenError.from(userAbilities).throwUnlessCan(ability.action, subject(ability.subject as any, subjectInstance));

Not really elegant solution but will do for now. Maybe @liquidautumn has more elegant ideas?

thanks

I also want to have this feature