Rocket.chat: Standardize how error messages are sent from the server

Created on 31 Mar 2016  路  8Comments  路  Source: RocketChat/Rocket.Chat

Today error messages thrown from the server are not standardized. For example:

I propose we thrown errors like the following:

  • the "error code" should be a hiphenized translatable message, like: invalid-username, not-authorized. This way our interface will take care of showing the correct translation for the error
  • the error message should be written in english and being human readable. This way, any interface (other than our web interface, like REST APIs) will have a printable message

@RocketChat/core thoughts?

i18n core improvement

All 8 comments

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:

  1. User is not logged in: error-user-logged-out: The user is logged out
  2. Operation is not allowed: error-not-allowed: Not allowed (instead of not-authorized)
  3. Not belonging to room: error-invalid-room: Invalid room

Any 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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lunitic picture lunitic  路  3Comments

neha1deshmukh picture neha1deshmukh  路  3Comments

djeber picture djeber  路  3Comments

Buzzele picture Buzzele  路  3Comments

karlprieb picture karlprieb  路  3Comments