2

This might be a silly question, how do you usually response to errors?

  1. Response with one error at a time or
  2. Response with multiple errors at a time, in a list record

Example

  • Invalid Email Address format
  • Invalid Phone number format
  • Invalid Password .etc...
  • Invalid API credentials

etc..

2 Answers 2

2

Your clients will appreciate it if you can design your validation responses in such a way that they can find out about all the errors at once rather than discovering them piecemeal.

I'll amend that to separate authentication/authorization issues from data validation. Those should not be together - no sense looking at any data if the person sending the request is neither authenticated nor authorized.

Sign up to request clarification or add additional context in comments.

8 Comments

Sure - you don't say if it's a SOAP server or not, but if it is just design an error response message that maps the errors to the data items in some way.
Thinking of returning a list of errors! but it does look complicated now. vs single error message returned one at a time.
When I report errors the way duffymo says -- it's the only way to do it right, imo -- I validate all of the inputs, collecting all of the errors and error messages. Then I complain about all of the errors in one response. The user can fix all his errors once and resubmit once, a very good thing.
It's not as complicated as it looks. If you think it through, you'll see that it can be straightforward, though perhaps not exactly trivial. Your users will appreciate your extra work.
how do you return the error, in a list? or do you return something like this "email1|invalid email format, please enter format [email protected], phonenumber|invalid phonenumber"
|
0

First something about exceptions.

The reasons you mentioned are exception details not the exception itself. If an operation fails (here, web method is going to do something, for example registering the user), there's only one exception (i.e RegistrationFailedException). All other things are it's information.

An Exception when occurs (I mean unhandled exceptions of course), no more exceptions can occur, so you should return the first and only unhandled exception with it's related information (event args).

Designing an Exception Schema is a good idea. Envelop exception and it's information in a single message according to your exception schema and return it to the user.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.