generate_invite_link API endpoint throws 500 if invite already redeemed

The following error occurs

NoMethodError (undefined method `invite_key' for nil:NilClass)
/var/www/discourse/app/models/invite.rb:82:in `generate_invite_link'

on this line: discourse/invite.rb at master · discourse/discourse · GitHub

It happens when trying to generate a link for a user that has already been invited. Perhaps it should return a 422, as inviting by email does, instead?

I’m trying to call these API endpoints from another application, and would like to differentiate between “already invited” and “server error”. The discourse frontend handles it pretty well though:



Pinging @techAPJ based on involvement in Copy Invite Link 🔗

Thanks for discourse being awesome!

1 Like

Hmm good point perhaps @techapj can improve the return codes here for API usage?

1 Like

Fixed via:

https://github.com/discourse/discourse/commit/f2c1dbaa6835b6def784a5dad6bb09a7b62b8751

4 Likes