-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
The service startup error could not be printed correctly #3101
Comments
🤖 Hello @cayller! I'm Dosu, a friendly bot here to assist you with your Kratos-related queries and concerns while we wait for a human maintainer. I'm here to help you solve bugs, answer questions, and guide you on becoming a contributor. Feel free to share more about your issue and I'll do my best to assist you! The issue you're experiencing seems to be related to the default error decoder in Kratos. The The problem arises when the context is canceled. In such cases, the HTTP client's To resolve this issue, you can create a custom error decoder that handles context cancellation errors separately. Here's an example: func CustomErrorDecoder(_ context.Context, res *http.Response) error {
if res.StatusCode >= 200 && res.StatusCode <= 299 {
return nil
}
if res == nil {
return errors.New("Context was canceled")
}
defer res.Body.Close()
data, err := io.ReadAll(res.Body)
if err == nil {
e := new(errors.Error)
if err = CodecForResponse(res).Unmarshal(data, e); err == nil {
e.Code = int32(res.StatusCode)
return e
}
}
return errors.Newf(res.StatusCode, errors.UnknownReason, "").WithCause(err)
} Then, when creating your client, use the client, err := NewClient(ctx, WithErrorDecoder(CustomErrorDecoder)) This way, when the context is canceled, your custom error decoder will return a more descriptive error message. You can find more information about this in the transport/http/client.go file in the Kratos repository. Sources |
What happened:
using register a custom server and using registrar, when custom server return a error, terminal can not print correct error description
What you expected to happen:
printing the correct error
but actually printing ctx canceled,because custom server return a error
How to reproduce it (as minimally and precisely as possible):
corresponding source code
Anything else we need to know?:
Environment:
kratos -v
):2.7.1go version
):1.21cat /etc/os-release
):The text was updated successfully, but these errors were encountered: