pre-defined) error message?
Consider the last error defined in one of my packages.
The last error will only be returned when page HTTP status code isn't 200
for example 500 or 403 or 503
But How can I attach the real status code to the error message?
Is that a framework code?
Go now supports wrapping errors with fmt.Errorf, so you could use fmt.Errorf("503 happened: %w", ErrBadStatusCode). This allows you to check for errors with errors.Is(err, ErrBadStatusCode). Before Go's support for these error checking utilities a lot of people relied on github.com/pkg/errors for the same functionality.
Обсуждают сегодня