Files
orchard/internal/responder/error.go
T
Nikolay Edigaryev 6a325daf74 Switch from golang.org/x/net/websocket to nhooyr.io/websocket and handle NotFound errors (#105)
* Switch from golang.org/x/net/websocket to nhooyr.io/websocket

* Do not attach errors that we can handle to the Gin's context

* Add missing newline to "no credentials specified or found, ..." message

* Fix potential NPE in ChooseUsernameAndPassword()

* Fix type in PortForward() error message in "orchard ssh vm"

* Fix potential NPE in Connections()

* Use header.Set() for consistency's sake for Authorization header
2023-07-04 18:10:41 +04:00

32 lines
526 B
Go

package responder
import (
"errors"
storepkg "github.com/cirruslabs/orchard/internal/controller/store"
"github.com/gin-gonic/gin"
"net/http"
)
type ErrorResponder struct {
err error
Responder
}
func Error(err error) Responder {
return &ErrorResponder{
err: err,
}
}
func (responder *ErrorResponder) Respond(c *gin.Context) {
var code = http.StatusInternalServerError
if errors.Is(responder.err, storepkg.ErrNotFound) {
code = http.StatusNotFound
} else {
_ = c.Error(responder.err)
}
c.Status(code)
}