WebService Error Handling

I use RestWebservice for several basic operations such as create / search. The xml request looks something like this:

<customer> 
    <name/>
  .....
 </customer>

For a successful operation, I return the same XML client with additional fields added to it (for example, systemId, etc., which we are empty in the request). with Response.Status = 2000

For an unsuccessful operation, I return something similar with different error codes. e.g. Response.Status = 422 (unprocessed object) Response.Status = 500 (Internal server error) and several others.

<errors>
<error> An exception occurred while creating the customer</error>
<error> blah argument is not valid.</error>
</errors>

Now I'm not sure if this is the right way to send errors to the client. Perhaps it should be present in the response header.

I will be very grateful for any help. Thank you

+3
2

XML "Request" "Response".

.

<customerrequest>
  <customer>
    ..
  </customer>
</customerrequest>

:

<customerresponse>
  <status>success | failure</status>
  <customer> <!-- If success -->
     ...
  </customer>
  <errors> <!-- If failure -->
     <!-- never underestimate the value of having a machine-friendly error code 
          for each possible error, or critical/non-critical errors -->
     <error code="0001">An error occurred</error>
  </errors>
</customerresponse>

, , /. . .

SOAP, , SOAP, ( , ).

+2

REST HTTP ( , ). ( ), , , .

, 2 . -, HTTP (. Wikipedia HTTP ), - HTTP - ; . ! , , - ( HTTP). , ( , ). , 5xx, .

- , : . ; , . , " ", ( HTTP).

+8

Source: https://habr.com/ru/post/1715898/


All Articles