MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / generateErrorHTML

Function generateErrorHTML

server/error_page.go:150–175  ·  view source on GitHub ↗

generateErrorHTML renders the error page template with the given error information. It returns the generated HTML as a byte slice and a Content-Type string. If there is an error during template execution or if the client does not accept HTML, it falls back to generating a plain text error message w

(err errctx.Error, reqID string, h http.Header)

Source from the content-addressed store, hash-verified

148// If there is an error during template execution or if the client does not accept HTML,
149// it falls back to generating a plain text error message with the error message and stack trace.
150func generateErrorHTML(err errctx.Error, reqID string, h http.Header) ([]byte, string) {
151 if !strings.Contains(h.Get(httpheaders.Accept), "text/html") {
152 return generateErrorText(err)
153 }
154
155 errorChain := unwrapErrorChain(err)
156 gover, commit := getBuildInfo()
157
158 data := errorPageData{
159 StatusCode: err.StatusCode(),
160 RequestID: reqID,
161 PublicMessage: err.PublicMessage(),
162 Version: version.Version,
163 Commit: commit,
164 GoVersion: gover,
165 ErrorChain: errorChain,
166 }
167
168 var buf bytes.Buffer
169 if errorPageTemplate.Execute(&buf, data) != nil {
170 // In case of template execution error, return the error message and stack trace as plain text.
171 return generateErrorText(err)
172 }
173
174 return buf.Bytes(), "text/html; charset=utf-8"
175}
176
177func generateErrorText(err errctx.Error) ([]byte, string) {
178 body := fmt.Appendf([]byte{}, "%s\n\n%s", err.Error(), err.FormatStack())

Callers 1

WithReportErrorMethod · 0.85

Calls 8

generateErrorTextFunction · 0.85
unwrapErrorChainFunction · 0.85
getBuildInfoFunction · 0.85
BytesMethod · 0.80
GetMethod · 0.65
StatusCodeMethod · 0.65
PublicMessageMethod · 0.65
ExecuteMethod · 0.45

Tested by

no test coverage detected