-
Notifications
You must be signed in to change notification settings - Fork 4
/
error.go
50 lines (41 loc) · 1.1 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (C) 2012 Numerotron Inc.
// Use of this source code is governed by an MIT-style license
// that can be found in the LICENSE file.
package bingo
import (
"errors"
"net/http"
)
type AppError struct {
Err error
Message string
Code int
}
func ServerError(err error, msg string) *AppError {
return &AppError{err, msg, 500}
}
func NewServerError(msg string) *AppError {
return ServerError(errors.New(msg), msg)
}
func NotFoundErr() *AppError {
return &AppError{errors.New("page not found"), "page not found", 404}
}
func Redirect(c Context, path string) *AppError {
WriteSessionCookie(c.Writer(), c.Session())
http.Redirect(c.Writer(), c.Request(), path, http.StatusFound)
return nil
}
func StoreAndRedirect(c Context, path string) *AppError {
// c.Session().Set("return_to", c.Request().URL.Path)
c.Session().Set("return_to", c.Request().URL.RequestURI())
return Redirect(c, path)
}
func RedirectToHttps(c Context) *AppError {
url := c.Request().URL
if !url.IsAbs() {
// XXX this has the port?
url.Host = c.Request().Host
}
url.Scheme = "https"
return Redirect(c, url.String())
}