stretchr / goweb

A lightweight RESTful web framework for Go
632 stars 61 forks source link

BeforeHandler.Before() where are errors returned to? #83

Closed tgreiser closed 10 years ago

tgreiser commented 10 years ago

On a controller, if Before() returns an error, where does that error go? If I do this I get an error/debug HTML page that looks like it's generated by goweb (in response to a JSON API request).

func (controller *SecureController) Before(ctx context.Context) error { if controller.Authenticate() == false { return errors.New("Authentication failed") } return nil }

I want to handle this authentication error myself, but I'm not sure how or where I should go about that.

<!DOCTYPE html>

Error in PATCH|OPTIONS users/{id} - 0x81c9070

Failed authentication

*errors.errorString error in Handler 0x18b78830

PATCH|OPTIONS users/{id} - 0x81c9070 
on adminuser-VirtualBox
matryer commented 10 years ago

You can use SetErrorHandler to explicitly handle errors yourself.

matryer commented 10 years ago

FYI - the DefaultErrorHandler is what writes that error page out - see https://github.com/stretchr/goweb/blob/master/handlers/default_error_handler.go#L24

tgreiser commented 10 years ago

Thank you!