fix: improve error handling in the error hook

- Updated the error handling logic in the tonic error hook to unwrap nested errors, ensuring that the most relevant error message is returned.
- Enhanced the clarity of the error response by directly using the unwrapped error message, improving debugging and user feedback.
This commit is contained in:
Marvin Zhang
2025-03-19 22:46:35 +08:00
parent c713416a91
commit e73ee2e387

View File

@@ -18,8 +18,12 @@ import (
func init() {
tonic.SetErrorHook(func(context *gin.Context, err error) (int, interface{}) {
unwrappedErr := errors.Unwrap(err)
if unwrappedErr != nil {
err = unwrappedErr
}
response := gin.H{
"error": errors.Unwrap(err).Error(),
"error": err.Error(),
}
status := http.StatusInternalServerError
constErr, ok := errors.AsType[errors.ConstError](err)