forked from gohugoio/hugo
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commands: Show server error info in browser
Fixes gohugoio#5284
- Loading branch information
Showing
24 changed files
with
353 additions
and
114 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
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
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,86 @@ | ||
// Copyright 2018 The Hugo Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package commands | ||
|
||
import ( | ||
"html/template" | ||
"io" | ||
) | ||
|
||
type errorTemplate struct { | ||
// To text template to produce a nice looking error page in the browser. | ||
templ string | ||
|
||
// The default HTTP status code shown for this error. | ||
statusCode int | ||
} | ||
|
||
var defaultBuildErrorTemplate = errorTemplate{ | ||
templ: `<!doctype html> | ||
<html class="no-js" lang=""> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Error</title> | ||
<style type="text/css"> | ||
body { | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; | ||
font-size: 16px; | ||
} | ||
main { | ||
margin: auto; | ||
max-width: 700px; | ||
padding: 1rem; | ||
} | ||
.stack { | ||
overflow: scroll; | ||
background-color: #eee; | ||
padding: 0.5rem; | ||
} | ||
.version { | ||
color: lightgray; | ||
padding-bottom: 1rem; | ||
} | ||
a { | ||
color: blue; | ||
text-decoration: none; | ||
} | ||
a:hover { | ||
color: black; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<main> | ||
<h1>{{ .Error.What }}</h1> | ||
<p><b>Error:</b> {{ .Error.Err }}</p> | ||
<div class="stack"> | ||
<!-<pre>{{/* .Error.Err.StackTrace */}}</pre>--> | ||
</div> | ||
<p class="version">{{ .Version }}</p> | ||
<a href="">Reload Page</a> | ||
</main> | ||
</body> | ||
</html> | ||
`, | ||
statusCode: 500, | ||
} | ||
|
||
func (templ errorTemplate) buildErrorPage(data interface{}, w io.Writer) error { | ||
t, err := template.New("").Parse(templ.templ) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return t.Execute(w, data) | ||
} |
Oops, something went wrong.