vendredi 17 février 2017

Same REST endpoint returning different Error Response Objects

My Client app is a consumer of REST Endpoint producing JSON Responses which can return error responses having different structures for different scenarios;

Error 1

{ 
    "errorCode" : "XXXX"
    "errorMessage" : "Validation Failed"
}//Note the lack of higher order key here; it's flat

Error 2

{
  "apiError" : {
    "errorCode" : "XXXX"
    "errorMessage" : "Validation Failed"
  }
}//Note "apiError" is an object 

Error 3

{
  "apiError" : [{
    "errorCode" : "XXXX"
    "errorMessage" : "Validation Failed"
  }]
}//Note "apiError" is a Collection 

As we see above few of the error responses have same key but with different return types;

"errorCode" are embedded within the different keys and are also not globally appearing at same level with JSON Response.

I'm a little clueless as how to approach this scenario? Is there any design pattern or any work around it?

Some guidance is appreciated.

Aucun commentaire:

Enregistrer un commentaire