scambra / devise_invitable

An invitation strategy for devise
MIT License
2.66k stars 553 forks source link

[Question] How to customise the json error message? #899

Closed Piioo closed 1 year ago

Piioo commented 1 year ago

Hello,

I let return devise invitable the responses as json with own controllerrespond_to :json.

How I may customise the structure of the error message like {"errors":{"invitation_token":["ist nicht gültig"]}}. I need an another structure.

I cant find the place where this is build.

scambra commented 1 year ago

DeviseInvitable is not generating any json, that's must be done by rails or responders gem

The controller uses respond_with(resource) when It fails, and the resource will have validation errors. Then respond_with must be generating that structure. I think respond_with comes from responders gem, you may ask there how to customize json in case of errors.

scambra commented 1 year ago

I give a look in responders gem, i think you can create your own responder, and define json_resource_errors to change the structure. https://github.com/heartcombo/responders/blob/main/lib/action_controller/responder.rb

You can see how to use your own responder in the readme https://github.com/heartcombo/responders/tree/main#configuring-your-own-responder

Piioo commented 1 year ago

Thanks