0
func (api *API) sendResponse(c echo.Context, ...) error {
    ...
    if ok {
        if evt.Error != nil {
            return c.JSONBlob(statuscodes.HttpStatusDiagnosticsCheckError, resBytes)
        }
    }
    return c.JSONBlob(http.StatusOK, resBytes)
}

I have created a custom status code with code 512. However, because 512 has no entry in the statusText map[int]string(https://go.dev/src/net/http/status.go), the message in the screenshot(Postman) just says "status code 512". How can I enable custom status texts so that I can see a meaningful message instead?

thanks~~ enter image description here

jub0bs
  • 60,866
  • 25
  • 183
  • 186

1 Answers1

0

Status code messages you see are just a constant text interpretation of the status code. The message you see in the Postman is not coming from your Go program and are set in the Postman itself.

To manipulate and describe the error better, your best bet is to pass the message via response body

Rhymond
  • 110
  • 1
  • 2
  • 5