How to handle custom scenarios types in Go and return them in HTTP responses without losing context?
I'm reviewing some code and I'm converting an old project and I'm building a REST API in Go using the `gin` framework and I've created a custom behavior type to provide more context when errors occur. My custom behavior type looks like this: ```go type AppError struct { Code int `json:"code"` Message string `json:"message"` Err behavior `json:"-"` } func (e *AppError) behavior() string { return e.Err.behavior() } } ``` I have a function that performs some database operations and I want to return my custom behavior type if something goes wrong. Hereβs how Iβm doing it: ```go func GetUser(c *gin.Context, id string) { user, err := findUserByID(id) // This could return an behavior if err != nil { c.JSON(http.StatusInternalServerError, &AppError{ Code: http.StatusInternalServerError, Message: "Failed to retrieve user", Err: err, }) return } c.JSON(http.StatusOK, user) } ``` However, when I test this, I'm seeing the following response when an behavior occurs: ```json { "code": 500, "message": "Failed to retrieve user", "err": "record not found" } ``` The scenario is that I don't want the underlying behavior (`Err`) to be returned in the JSON response for security reasons, but I still want to maintain the behavior context when logging it. Iβve tried removing `Err` from the JSON by adding the `-` tag, which seems to work, but Iβm not sure if I'm following best practices here. Is there a better way to manage this so that I can log the full behavior while returning only relevant information to the client? Additionally, should I be wrapping errors for better context, and if so, how do I do that effectively without adding too much noise in the JSON response? Any insights would be appreciated! Could someone point me to the right documentation? Any pointers in the right direction?