-
Notifications
You must be signed in to change notification settings - Fork 153
Service communication exception handling #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Service communication exception handling #94
Conversation
|
||
#### Error code as HTTP status code or in message | ||
|
||
Some APIs put status code in the HTTP response code (introduce custom codes). I don't have strong openion on this, so I went with approach that Facebook, Twitter and Twilio use. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should put response code as HTTP code and in the response. In the future, if the communication protocol changes (for ex. a message queue will be used), we won't need to change the response format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure it would work for all protocols, in RPC you always should return 200 response code.
Pros | ||
* Error codes make sense regardless of technology | ||
Cons | ||
* We would have to maintain some sort of mapping to make it work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, most of the exceptions will be the same, I think it's not a big deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think mapping should be per API endpoint. Anyway, I agree that it's not a big problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mapping will still require additional effort for microservice deployment support from our developers and, most importantly, extension developers
|
||
When we consume services in BFF we could benefit from knowing that network exception happen, because we could make UI more friendly. For instance, we were not able to calculate totals on shopping cart page. We can still show shopping art and display the message that we retrying total calculation. | ||
|
||
In order to make this improvements in UI, we would have to declare new type of exception on service contracts `DataRetrievalFailedException`. This is would be backwards incompatible change for monolith. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this exception work only for GET operations? What about POST, PUT, DELETE? I think, for the service, the exception might be the same as now NotFoundException
, CouldNotSaveException
, etc. Because the service doesn't know about the network communication. In general, the service might be called via REST, a message queue, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't replace DataRetrievalFailedException
with NotFoundException
because you may need to handle them differently. I will think about exceptions for POST, PUT and DELETE methods.
Pros | ||
* No mapping needed, exceptions from API can easily be caught or thrown | ||
Cons | ||
* If consumer or producer service has non PHP or Magento implementation PHP exception class name doesn't make a lot of sense |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While exception class names wouldn't make a difference for services produced without Magento an exception class is still as good identifier of error as a number ID. But having exception class names will also make it easier for services using Magento - it's a win-win solution
</TwilioResponse> | ||
``` | ||
|
||
### Exception class name or class name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Exception class name or class name | |
### Exception class name or error code |
|
||
For now, I suggest to go with option #1. If we would want to handle network communication exceptions in UI, we could do #5 or #2. | ||
|
||
### Limiting amount of services to deploy after adding new exception in our of the producers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
|
||
Return exception class names | ||
Pros | ||
* No mapping needed, exceptions from API can easily be caught or thrown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lists are formatted incorrectly
|
||
In order to make this improvements in UI, we would have to declare new type of exception on service contracts `DataRetrievalFailedException`. This is would be backwards incompatible change for monolith. | ||
|
||
Possible options: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can extend new exceptions from LocalizedException, which is already declared for most of the services. Then it will be backward compatible change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We declare derived classes of LocalizedException but not LocalizedException on most of the interfaces. And I think we should use LocalizedException only in presentation layer.
|
||
### Exception class name or class name | ||
|
||
Existing REST API returns only error message, so we need to add exception class name or error code in addition to HTTP response code. This would allow different consumers of the service handle errors or understand what exception need to be handled or which exception type need to be thrown. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please describe specific use cases when having existing HTTP status codes + error messages is not enough?
BTW, in current implementation codes are not implemented on purpose because we have a way to distinguish exceptions on the client based on the message template (which has placeholders instead of real variable names). So there is a way to distinguish different exception instances, however there is no way to distinguish exception classes. It is also possible to distinguish specific exceptions like Authorization, Authentication, Not Found, Internal Server error and maybe some others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a mapping of message texts to exceptions is not convenient. Also the fact that messages can be used to understand what type of exception is thrown might be confusing, having error codes is common practice. I personally didn't know that you can depend on message text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is legacy architecture. We need to weight pros and cons of introducing alternative.
Will reopen after we clarify technical direction. |
Problem
Solution
Requested Reviewers