This is fine and doesn't need changing (apart from making the status code 400, please)
This condition can't happen, because it's always possible to extract a via from the user who sent the invite. Remove the if statement and just always use the more detailed error message.
Third parameter needs to be an object, so I fixed that for you. I also labelled the inbound parameters so that it highlights the call site if the wrong data is passed to joinRoom. :)
I fixed path so that passing arrays (like via) to it should work correctly. :)
I added a separate branch for it to say a different error message when the join fails. I felt the ternary was too complicated.
or if we should add a "please consider manually inviting
I…