updated hws: expanded error page functionality
This commit is contained in:
@@ -31,7 +31,7 @@ const (
|
||||
|
||||
// ErrorPageFunc is a function that returns an ErrorPage with the specified HTTP Status code
|
||||
// This will be called by the server when it needs to render an error page
|
||||
type ErrorPageFunc func(errorCode int) (ErrorPage, error)
|
||||
type ErrorPageFunc func(error HWSError) (ErrorPage, error)
|
||||
|
||||
// ErrorPage must implement a Render() function that takes in a context and ResponseWriter,
|
||||
// and should write a reponse as output to the ResponseWriter.
|
||||
@@ -40,11 +40,11 @@ type ErrorPage interface {
|
||||
Render(ctx context.Context, w io.Writer) error
|
||||
}
|
||||
|
||||
// TODO: add test for ErrorPageFunc that returns an error
|
||||
// AddErrorPage registers a handler that returns an ErrorPage
|
||||
func (server *Server) AddErrorPage(pageFunc ErrorPageFunc) error {
|
||||
rr := httptest.NewRecorder()
|
||||
req := httptest.NewRequest("GET", "/", nil)
|
||||
page, err := pageFunc(http.StatusInternalServerError)
|
||||
page, err := pageFunc(HWSError{StatusCode: http.StatusInternalServerError})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "An error occured when trying to get the error page")
|
||||
}
|
||||
@@ -88,7 +88,7 @@ func (server *Server) ThrowError(w http.ResponseWriter, r *http.Request, error H
|
||||
}
|
||||
if error.RenderErrorPage {
|
||||
server.LogError(HWSError{Message: "Error page rendering", Error: nil, Level: ErrorDEBUG})
|
||||
errPage, err := server.errorPage(error.StatusCode)
|
||||
errPage, err := server.errorPage(error)
|
||||
if err != nil {
|
||||
server.LogError(HWSError{Message: "Failed to get a valid error page", Error: err})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user