substance / notes

Real-time collaborative notes editing.
Other
21 stars 5 forks source link

Consistent error handling #42

Closed michael closed 8 years ago

michael commented 8 years ago

We need a consistent way to describe errors. Errors that happen on the server should have the same format as on the client. I currently use new Error('some message') to represent errors. In order to expose them to the client I use a json serialization.

res.status(500).json({errorMessage: err.message});

On the client I turn it back into a rich error object.

      // $.ajax call
      ...
      error: function(err) {
        cb(new Error(err.responseJSON.errorMessage));
      }

We may want to switch to a custom SubstanceError class that stores a an errorCode (e.g. 'authentication-failed') which we can translate to a human-readable string using this.i18n.t.

@oliver---- thoughts?

michael commented 8 years ago

That still needs work but we have a solution now that does not expose any server internals to the client.