SOAP error or result object?

I discussed this with an employee, and we could not agree, so I wanted to get your thoughts. I have my own opinions on this, but I will not ruin it.

When should I return a SOAP error and when should I return an object containing error information? Suppose this is for a general web service that can be used by various systems (.NET, Java, independently). The result object has an isError flag, an errorType type (similar to a specific type of exception), and a message.

Some points to consider:

  • Is a data validation error an error?
  • Should there be a combination of errors (for very exceptional cases) and a result object (for "expected" errors)?
  • How would you group SOAP errors (critical [null link] versus validation [wrong postcode])?
  • Fail-fast vs must be remembered to check for errors
  • Best practices, templates, standards, etc.

Links to articles are valid. Even if it sounds like I want your opinion, please stick to the facts (better x because of y and z ...)

+54
exception-handling web-services soapfault
May 12 '10 at 10:05 p.m.
source share
4 answers

Most SOAP clients translate errors into runtime exceptions (if that is what the client language supports). With that in mind, I think you could rephrase the question as "When do I want to throw an exception, instead of returning the error value"? I am sure that you can find many opinions about this API design in general and in this topic in particular.

However, returning an error usually does not help the client:

  • The client needs to manually list and process the error codes compared to the stub code being generated and choosing the appropriate exception type. Using error codes prevents the client from using object-oriented methods, such as handling exceptions using the superclass.

  • If you do not make your error codes part of the WSDL; the client will not have documentation about what they are or when they occur. Typed errors are part of WSDL and therefore (to some extent) self-documenting.

  • Fault messages may contain a situation-specific context that the client can use for error reporting and recovery. For example, resetting an input validation error containing a valid invalid input element and reason. If you return the result with an error code and an opaque string, the client has little choice but to pass the error message to the user, which violates internationalization, user interface consistency, etc.

To answer your specific questions:

  • Verification error is an error. Imagine if you are calling a web service from an AJAX client with limited error handling capability; you want the service to return an HTTP 5xx code, not a 400 success code with an unexpected response.

  • No. APIs must provide consistent error reporting interfaces. WSDL design is an API design. Forcing the client to implement two different error handlers does not make life easier for the client.

  • The failure design should reflect your request / response model and display information corresponding to the service abstraction. Do not throw a NullReference error; design XYZServiceRuntimeFault. If clients often provide incorrect requests, create an InvalidRequestFault with the appropriate subclasses so that clients can quickly determine where the invalid data is.

+54
Jun 21 '10 at 18:17
source share
— -

The result object should contain only results. If your result object provides a list of errors that occurred on another system, this is an example of when you can have the "isError" flag; otherwise you cannot, because the result is valid or not.

You should always use SOAPFault when an error occurs. Validation is a mistake, and this is the devil's trap who believes that the verification is reliable as less serious than the inability to open the database. Both cases have the same effect - the operation cannot be performed on request.

Therefore, you must use result objects for results and SOAP Faults for anything that interferes with the actual result object; including, but not limited to, errors, verification errors, warnings, bus errors, etc.

In the previous days there were no exceptions, and as a result, many APIs became incompatible, and most APIs differed in how to return the error. It was (and still is) terrible, confusing and often slowing down because you need to look for how each API entry returns an error, and often how to decrypt or learn more about the error.

+39
Jun 22 '10 at 2:30 p.m.
source share

I think the short answer is a soap error, if you do not know that the client will be equipped to handle the error returned as a result. I also thought about the analogy between exceptions and error results, as mentioned in other answers.

There are gray areas that could reasonably be considered as exceptions and as result errors depending on the needs of the client. You can then provide a parameter to a service that changes the way these types of errors return. By default, a SOAP error is used, but if the client sets a parameter to receive the error results, it indicates that it is ready to handle this as part of the result. For me, validation errors in this gray area. For most clients, they should be considered as malfunctions, but if the client wants to use the data for the user interface layout with verification errors, then returning verification errors, as part of the result can be more useful.

+7
Jun 25 '10 at 17:40
source share

The rule that I adhere to in service design is as follows:

  • business level response (even business exceptions) to response objects
  • technical / level of integration errors in soap error

A service consumer can rely on the fact that every business response comes in response objects and presents it to service (business) users. Soap errors are used only when the business response cannot be delivered.

Soap bugs should trigger a warning / support action through monitoring.

+1
Feb 14 '17 at 15:25
source share



All Articles