Example #1
0
func New() *Handler {
	return &Handler{
		router:  NewRouter(),
		options: &Options{ErrorFormatter: &errors.JsonFormatter{}},
		logger:  logutils.New(logutils.ConsoleFilter),
	}
}
Example #2
0
// Utility functions for producing errorneous http responses
package errors

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

	"github.com/kapalhq/envoy/logutils"
)

const (
	StatusTooManyRequests = 429
)

var log = logutils.New(logutils.ConsoleFilter)

type ProxyError interface {
	GetStatusCode() int
	Error() string
}

type Formatter interface {
	Format(ProxyError) (statusCode int, body []byte, contentType string)
}

type JsonFormatter struct {
}

func (f *JsonFormatter) Format(err ProxyError) (int, []byte, string) {
	encodedError, e := json.Marshal(map[string]interface{}{
		"error": string(err.Error()),