I'm designing an application in a micro-service architecture and I have some questions regarding error codes.
Found some information about it (1,2) - but more focused on the responsibility of the error code management.
Suppose I have 2 micro-services and an API Gateway. At current design - each micro-service is defining it's own error codes with a define prefix where there are 2 types of errors:
- General Errors
- Fields Validation Errors
For example:
Projects Micro Service Error Responses:
{
"status": 1,
"error": {
"error_code": "a_133",
"error_str": "project not exists"
}
}
{
"status": 1,
"error": {
"error_code": "a_2",
"error_str": "invalid parameters",
"error_fields": {
"project_name": "project name is too short",
"project)date": "invalid date format"
}
}
}
Billing Micro Service Error Response:
{
"status": 1,
"error": {
"error_code": "b_243",
"error_str": "billing validation was failed"
}
}
Every "create" endpoint that is created in Projects or Billing Micro services should be handled also in the GW - where this micro-service is usually forwards the requests after authenticating the user.
My question is how it should handle the error codes? Should it forward the errors he got from the micro-services or it needs to translate them into his own set of errors? making a lot of conversion code - specially when dealing with "Fields Validation Errors".
What's the best practice here?