'How to put meaningful custom status text for custom status codes in Go's echo framework?

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



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rhymond