A simple page for all your links.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

37 lines
800 B

  1. package publicbio
  2. import (
  3. "github.com/writeas/impart"
  4. "log"
  5. "net/http"
  6. )
  7. type handlerFunc func(app *App, w http.ResponseWriter, r *http.Request) error
  8. func (app *App) handler(h handlerFunc) http.HandlerFunc {
  9. return func(w http.ResponseWriter, r *http.Request) {
  10. handleError(w, r, func() error {
  11. return h(app, w, r)
  12. }())
  13. }
  14. }
  15. func handleError(w http.ResponseWriter, r *http.Request, err error) {
  16. if err == nil {
  17. return
  18. }
  19. if err, ok := err.(impart.HTTPError); ok {
  20. log.Printf("Error: %v", err)
  21. if err.Status >= 300 && err.Status < 400 {
  22. impart.WriteRedirect(w, err)
  23. return
  24. }
  25. impart.WriteError(w, err)
  26. return
  27. }
  28. log.Printf("Error: %v", err)
  29. impart.WriteError(w, impart.HTTPError{http.StatusInternalServerError, "We encountered an error we couldn't handle."})
  30. }