Welcome to mirror list, hosted at ThFree Co, Russian Federation.

errors.go « serverless « serving « internal - gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d208a11df2f042b8492c3dfdf10f0b8af5774461 (plain)
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
package serverless

import (
	"encoding/json"
	"net/http"
)

// NewErrorHandler returns a func(http.ResponseWriter, *http.Request, error)
// responsible for handling proxy errors
func NewErrorHandler() func(http.ResponseWriter, *http.Request, error) {
	return func(w http.ResponseWriter, r *http.Request, err error) {
		w.WriteHeader(http.StatusInternalServerError)

		message := "cluster error: " + err.Error()
		msgmap := map[string]string{"error": message}

		json, err := json.Marshal(msgmap)
		if err != nil {
			w.Write([]byte(message))
			return
		}

		w.Header().Set("Content-Type", "application/json")
		w.Write(json)
	}
}