fix: check if Error is null in json response
This commit is contained in:
parent
8e6c578dbd
commit
03c5908605
@ -12,12 +12,18 @@ func HandleError(c *gin.Context) func(error) any {
|
||||
return func(err error) any {
|
||||
// Check if the error is of type *AppError
|
||||
if appErr, ok := err.(*app_error.AppError); ok {
|
||||
// Use the AppError fields for the JSON response
|
||||
c.JSON(appErr.Status, gin.H{
|
||||
response := gin.H{
|
||||
"code": appErr.Code,
|
||||
"message": appErr.Message,
|
||||
"details": appErr.Err.Error(), // Original error if available
|
||||
})
|
||||
}
|
||||
|
||||
// Add details if available
|
||||
if appErr.Err != nil {
|
||||
response["details"] = appErr.Err.Error()
|
||||
}
|
||||
|
||||
// Use the AppError fields for the JSON response
|
||||
c.JSON(appErr.Status, response)
|
||||
} else {
|
||||
// Fallback for non-AppError errors
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
|
Loading…
x
Reference in New Issue
Block a user