feat: add panic recovery middleware (#3687)

This commit is contained in:
Jon Ayers
2022-08-29 17:00:52 -05:00
committed by GitHub
parent 3cf17d34e7
commit 053fe6ff61
13 changed files with 471 additions and 40 deletions

View File

@ -59,6 +59,18 @@ func Forbidden(rw http.ResponseWriter) {
})
}
func InternalServerError(rw http.ResponseWriter, err error) {
var details string
if err != nil {
details = err.Error()
}
Write(rw, http.StatusInternalServerError, codersdk.Response{
Message: "An internal server error occurred.",
Detail: details,
})
}
// Write outputs a standardized format to an HTTP response body.
func Write(rw http.ResponseWriter, status int, response interface{}) {
buf := &bytes.Buffer{}