-
Notifications
You must be signed in to change notification settings - Fork 14
Basic Error Handler #19
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
Comments
Is the Of course, I agree that if there is no message the Http error code should be displayed. Exemple with your suggestion in python with error message:
In case without error message :
|
After discussing we think (in the majority) that we should display as much information as possible, especially because we are doing a basic error handler. Plus, this information is display only with the interpreter, so for debugging. |
143: Rename MeiliSearch\HTTPRequestException into MeiliSearch\ApiException r=bidoubiwa a=claudiunicolaa Rename `MeiliSearch\HTTPRequestException` into `MeiliSearch\ApiException` Explained here meilisearch/integration-guides#19 and discussed here #50. I hope I understood correctly your intention 😃 Co-authored-by: Claudiu Nicola <[email protected]>
144: Add MeiliSearch\Exceptions\CommunicationException r=bidoubiwa a=claudiunicolaa Add a new exception. It will handle the connection errors as explained here meilisearch/integration-guides#19. `Http\Client\Exception\NetworkException` exceptions will be catch and resend as `MeiliSearch\Exceptions\CommunicationException` Co-authored-by: Claudiu Nicola <[email protected]> Co-authored-by: claudiunicolaa <[email protected]>
144: Add MeiliSearch\Exceptions\CommunicationException r=bidoubiwa a=claudiunicolaa Add a new exception. It will handle the connection errors as explained here meilisearch/integration-guides#19. `Http\Client\Exception\NetworkException` exceptions will be catch and resend as `MeiliSearch\Exceptions\CommunicationException` Co-authored-by: Claudiu Nicola <[email protected]> Co-authored-by: claudiunicolaa <[email protected]>
Closing this since it's finally implemented everywhere :D |
Uh oh!
There was an error while loading. Please reload this page.
I create this issue as a continuation of this one that is an investigation specifically about naming for error handling 🙂
The goal of this issue is to detail the basic requirements of the SDKs error handlers.
I would like to keep this discussion as clear as possible, it means if you think I forgot basic points you can continue the discussion here with really clear explanations. Or you can contact me directly (if you can) so that I can update this post 😊
Goal
The goal of an error handler in an SDK is to say to the user "this package (so MeiliSearch) you are using, among the multitude of packages, raises an error".
That's why our SDK should not return an
Axios
(JS client library) orHttparty
(equivalent in ruby) error. Otherwise, it becomes complicated for the user to understand where exactly the error comes from.What kind of error?
The name of the error is really important, and should give 2 pieces of information:
MeiliSearch
Following the previous issue about error handler naming, here are the 3 minimum errors the SDKs should raise:
MeiliSearchApiError
: MeiliSearch (HTTP) sends back a4xx
or a5xx
. There are most of the SDKs errors.MeiliSearchCommunicationError
: problem with communication, for example, the MeiliSearch instance is unreachable.MeiliSearchError
: for any other errors in the SDK (wrong parameter if the SDK checks the parameters...etc)Remark
Some language allows namespacing. So the raised error could be
MeiliSearch::ApiError
instead ofMeiliSearchApiError
. It depends on the language. We should adopt the best practice of each language 🙂For example, in the Ruby and PHP SDKs, we used the namespace
MeiliSearch
.In the JS one, we use the prefix
MeiliSearch
instead, directly in the name of the error.Also, depending on the language, the
Error
could be changed asException
for example (ex: PHP).Another suggestion:
Even if we define a generic
MeiliSearchApiError
we can also define more specific errors concerning the API. I particularly think about an error forThis index already exists
.But I suggest we talk about that in another issue once all the SDKs will have their own error handler according to this issue 🙂
Just telling this is possible 😉
What kind of display with the language interpreter?
The name of the raised error is great, but not enough. We should display at least an error message.
In the case of the generic
MeilISearchApiError
, the expection message has to be the message of the MeiliSearch (HTTP) response.Again for the generic
MeiliSearchApiError
, if it's possible, we should also display the HTTP code error. I say "if it's possible" because all the language interpreter does not use the same way to display exception raising. We should at least manage to display the error message 🙂
(I know, the naming `MeiliSearch HTTPRequestException` should be `MeiliSearch ApiException`)Which methods?
Depending on the good practices of each language, we should also provide methods in our custom errors. The goal of these methods is to help the user during his/her code implementation and for debugging.
Generally, a
to_sring
ormessage
method has to be implemented.For example, with the PHP example, the
__toString
method is the method called by the interpreter to display the raising exception.For the generic
MeiliSearchApiError
, a method/attribute should be provided for the HTTP code (ex:httpCode
) and for the HTTP message response (ex:httpMessage
ormessage
).Final words
The goal of this issue is to stay basic, that's why I did not detail more what to do, especially because it depends a lot on each language.
If some methods or other kind of error implementation seems really essential to you, it will deserve its own issue on this repository 🙂 We should stay simple for the beginning with these 3 kinds of error.
Tell me if some parts are not clear to you, deserve more explanation, or if I forgot some problematic points in my logic.
TODO on different SDKs
The text was updated successfully, but these errors were encountered: