mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-04-27 15:07:43 +00:00
Email me for internal errors.
This commit is contained in:
parent
b3887d60b6
commit
fc216fb3de
1 changed files with 31 additions and 0 deletions
31
app/app.go
31
app/app.go
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"appengine"
|
"appengine"
|
||||||
|
"appengine/mail"
|
||||||
|
|
||||||
"github.com/google/go-github/github"
|
"github.com/google/go-github/github"
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
|
|
@ -208,12 +209,42 @@ func handleAppError(e *AppError, w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
if e.Type != AppErrorTypeBadInput {
|
if e.Type != AppErrorTypeBadInput {
|
||||||
c.Errorf("%v", e.Error)
|
c.Errorf("%v", e.Error)
|
||||||
|
sendAppErrorMail(e, r)
|
||||||
} else {
|
} else {
|
||||||
c.Infof("%v", e.Error)
|
c.Infof("%v", e.Error)
|
||||||
}
|
}
|
||||||
http.Error(w, e.Message, e.Code)
|
http.Error(w, e.Message, e.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sendAppErrorMail(e *AppError, r *http.Request) {
|
||||||
|
session, _ := sessionStore.Get(r, sessionConfig.CookieName)
|
||||||
|
userId, _ := session.Values[sessionConfig.UserIdKey].(int)
|
||||||
|
|
||||||
|
errorMessage := &mail.Message{
|
||||||
|
Sender: "RetroGit Admin <digests@retrogit.com>",
|
||||||
|
To: []string{"mihai.parparita@gmail.com"},
|
||||||
|
Subject: fmt.Sprintf("RetroGit Internal Error on %s", r.URL),
|
||||||
|
Body: fmt.Sprintf(`Request URL: %s
|
||||||
|
HTTP status code: %d
|
||||||
|
Error type: %d
|
||||||
|
User ID: %d
|
||||||
|
|
||||||
|
Message: %s
|
||||||
|
Error: %s`,
|
||||||
|
r.URL,
|
||||||
|
e.Code,
|
||||||
|
e.Type,
|
||||||
|
userId,
|
||||||
|
e.Message,
|
||||||
|
e.Error),
|
||||||
|
}
|
||||||
|
c := appengine.NewContext(r)
|
||||||
|
err := mail.Send(c, errorMessage)
|
||||||
|
if err != nil {
|
||||||
|
c.Errorf("Error %s sending error email.", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Template struct {
|
type Template struct {
|
||||||
*template.Template
|
*template.Template
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue