Best practice to handle API HTTP response
Hi,
When you call a REST API and have such a reply below. How would the best pratice to cast the response to a CDT please ?
Do you consider this ER must always return a generic CDT reply (solution A),
or do you consider this ER must return 2 different CDTs according the reply, but in this case, we would have to handle a condition (Solution B)
Response Ok from API :
body: {
"id" : 1212
"url" : "https...."
}
Error Response from API :
body: {
"developerMessage": "file already used",
"errorCode":102
}
Solution A :
type!response(
OK: { /* Filled if OK */
id : 1212
url : "https...."
},
ERROR { /* Filled when Error */
developerMessage: "file already used",
errorCode: 102
}
Solution B : 2 different CDTs
type!errorResponse(
developerMessage: "file already used",
errorCode: 102
)
type!response(
id : 1212
url : "https...."
)
