forked from getlantern/lantern
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding "Address not found" generic page.
- Loading branch information
Showing
6 changed files
with
379 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
250 changes: 250 additions & 0 deletions
250
src/github.com/getlantern/flashlight/status/resources.go
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package status | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"html/template" | ||
"strings" | ||
) | ||
|
||
type cannotFindServerT struct { | ||
ServerName string | ||
ErrorMessage string | ||
} | ||
|
||
func normalizeError(err error) string { | ||
if err != nil { | ||
content := strings.SplitN(strings.TrimSpace(err.Error()), "\n", 2) | ||
return strings.TrimSpace(content[0]) | ||
} | ||
return "" | ||
} | ||
|
||
// CannotFindServer creates and returns a generic "cannot find server" error. | ||
func CannotFindServer(server string, errMessage error) ([]byte, error) { | ||
var err error | ||
var buf []byte | ||
var tmpl *template.Template | ||
|
||
if errMessage == nil { | ||
errMessage = errors.New("Unknown error.") | ||
} | ||
|
||
buf, err = Asset("generic_error.html") | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
tmpl, err = template.New("status_error").Parse(string(buf)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
data := cannotFindServerT{ | ||
ServerName: server, | ||
ErrorMessage: normalizeError(errMessage), | ||
} | ||
|
||
out := bytes.NewBuffer(nil) | ||
|
||
if err = tmpl.Execute(out, data); err != nil { | ||
return nil, err | ||
} | ||
|
||
return out.Bytes(), nil | ||
} |
Oops, something went wrong.