Which "error messages" are you referring to? You should not change the HTTP Status Code (e.g. 404).
TMF630 v4.2.0 section 3.4 describes User, Application and Extended Error Codes which are provided as a JSON object in the body of the response:
{
"code":
"reason":
"message":
"status":
"reference":
"@type":
"@schemaLocation":
}
You could tailor this however the question becomes: based on what? If your server responds differently from request to request it breaks determinism. The proper way to handle that is to use Media Types. TMF630 specifies application/json
however you could use Content Negotiation to add additional types. We do this at SigScale to allow clients to request IETF Problem Details (RFC7807) encoding, as used by 3GPP and ETSI (see AP-2628). The client would add the media type (application/problem+json
) to it's accepted media types in the request:
POST /productOrder
Content-Type: application/json
Accept: application/problem+json, application/json
This tells the server that a response body may contain the IETF Problem details JSON object or the TMF Forum JSON object. The server response shall indicate which in the Content-Type header:
HTTP/1.1 400 Bad Request
Content-Type: application/problem+json
You could use your own media type(s) (e.g. application/vnd.acme.problem
) or you could extend the TMF type with a parameter (e.g. schema=acmeError
) (although RFC4627 doesn't specify any, so this is an invention):
POST /productOrder
Content-Type: application/json
Accept: application/json;schema=AcmeError
You could then extend the JSON Schema (Common/Error.schema.json
) polymorphically with whatever extra attributes you wanted:
{
"@type": "AcmeError",
"@schemaLocation": "/schema/AcmeError.schema.json",
"acmeCode": 42,
...
}
If you use a polymorphic extension you wouldn't need to use content negotiation as all as long at it's OK to send the same extended response to all clients. Clients which don't understand AcmeError
should ignore the extra attributes, however they may request exactly the type (i.e. AcmeError) they prefer to accept.
------------------------------
Vance Shipley
SigScale
------------------------------
Original Message:
Sent: Oct 31, 2023 12:02
From: Manaswini Jayaraman
Subject: Error handling for different consumers of same API
Hello,
If there is a TMF API (say TMF622) which is used for different consumers and each consumer expects different error messages for the same functionality, can someone advice on what the best way is for error handling?
For now, we have these 2 options on mind:
- Hard coding the different error messages per consumer
- Creating a reference data, to differentiate the error messages per consumer, even if there is no reuse (today).
Thanks in advance!
#OpenDigitalArchitecture
------------------------------
Manaswini Jayaraman
Proximus SA
------------------------------