goproxy/pkg/proxy/response.go

25 lines
476 B
Go
Raw Normal View History

2018-12-24 07:51:40 +00:00
package proxy
2018-09-01 04:23:32 +00:00
import (
"fmt"
2018-12-24 07:51:40 +00:00
"log"
2018-09-01 04:23:32 +00:00
"net/http"
2018-09-05 05:31:00 +00:00
"os"
2018-09-01 04:23:32 +00:00
)
2018-12-24 07:51:40 +00:00
var errLogger = log.New(os.Stderr, "", log.LstdFlags)
2018-09-01 04:23:32 +00:00
func ReturnServerError(w http.ResponseWriter, err error) {
w.WriteHeader(500)
msg := fmt.Sprintf("%v", err)
2018-12-24 07:51:40 +00:00
errLogger.Printf("goproxy: %s\n", msg)
_, _ = w.Write([]byte(msg))
2018-09-01 04:23:32 +00:00
}
2018-09-06 01:19:18 +00:00
func ReturnBadRequest(w http.ResponseWriter, err error) {
w.WriteHeader(400)
msg := fmt.Sprintf("%v", err)
2018-12-24 07:51:40 +00:00
errLogger.Printf("goproxy: %s\n", msg)
_, _ = w.Write([]byte(msg))
2018-09-06 01:19:18 +00:00
}