Today error messages thrown from the server are not standardized. For example:
[method] prefix of an untraslated messageI propose we thrown errors like the following:
invalid-username, not-authorized. This way our interface will take care of showing the correct translation for the error@RocketChat/core thoughts?
I agree, just thing that erro codes code start with "error-" so they will be grouped on the i18n.json files.
Does this applies only to erros or to all messages returned to method calls?
To any exception thrown with Meteor.Error
I agree we start using "error-..." on error codes (eg.: error-invalid-room). Error message should be english and without any reference to the method being called. So, instead of "[method] archiveRoom -> Invalid room.", we should use "Invalid room.".
If we can pass more debug information as a 3rd parameter, I agree in removing the "[method] name ->" from the API messages.
We can pass a 3rd parameter. I'll add { method: 'methodName' } to the error details. Can anyone think of any other info to get into details object? eg.: throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'archiveRoom' }).
We should define some standards, such as what error to throw when user is not logged in, or when the operation is not allowed because the user lacks permission, or when the user doesn't belong to the room, etc.
So, I vote for:
error-user-logged-out: The user is logged outerror-not-allowed: Not allowed (instead of not-authorized)error-invalid-room: Invalid roomAny other suggestions?
Or maybe using proper error codes could be better.
So, instead of throw new Meteor.Error('error-user-logged-out', 'The user is logged out', { method: 'methodName' });, we could call throw new Meteor.Error(403, 'Forbidden', { method: 'methodName' });
That would also be the case for not being allowed or not belonging to room... in whichever case, the user is forbidden to do that action. Any specific errors would still use the error-* pattern, so error-name-is-required would translate to Name is required
I dont think http error codes are clear enough for our use cases.