Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use InternalServerError (500) instead of GatewayTimeoutError (504). #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions chi/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ func (g *ChiLambda) Proxy(req events.APIGatewayProxyRequest) (events.APIGatewayP
chiRequest, err := g.ProxyEventToHTTPRequest(req)

if err != nil {
return core.GatewayTimeout(), core.NewLoggedError("Could not convert proxy event to request: %v", err)
return core.InternalServerError(), core.NewLoggedError("Could not convert proxy event to request: %v", err)
}

respWriter := core.NewProxyResponseWriter()
g.chiMux.ServeHTTP(http.ResponseWriter(respWriter), chiRequest)

proxyResponse, err := respWriter.GetProxyResponse()
if err != nil {
return core.GatewayTimeout(), core.NewLoggedError("Error while generating proxy response: %v", err)
return core.InternalServerError(), core.NewLoggedError("Error while generating proxy response: %v", err)
}

return proxyResponse, nil
Expand Down
7 changes: 6 additions & 1 deletion core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import (
"github.com/aws/aws-lambda-go/events"
)

// GatewayTimeout returns a dafault Gateway Timeout (504) response
// GatewayTimeout returns Gateway Timeout (504) response
func GatewayTimeout() events.APIGatewayProxyResponse {
return events.APIGatewayProxyResponse{StatusCode: http.StatusGatewayTimeout}
}

// InternalServerError returns Internal Server Error (500) response
func InternalServerError() events.APIGatewayProxyResponse {
return events.APIGatewayProxyResponse{StatusCode: http.StatusInternalServerError}
}

// NewLoggedError generates a new error and logs it to stdout
func NewLoggedError(format string, a ...interface{}) error {
err := fmt.Errorf(format, a...)
Expand Down
4 changes: 2 additions & 2 deletions gin/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ func (g *GinLambda) Proxy(req events.APIGatewayProxyRequest) (events.APIGatewayP
ginRequest, err := g.ProxyEventToHTTPRequest(req)

if err != nil {
return core.GatewayTimeout(), core.NewLoggedError("Could not convert proxy event to request: %v", err)
return core.InternalServerError(), core.NewLoggedError("Could not convert proxy event to request: %v", err)
}

respWriter := core.NewProxyResponseWriter()
g.ginEngine.ServeHTTP(http.ResponseWriter(respWriter), ginRequest)

proxyResponse, err := respWriter.GetProxyResponse()
if err != nil {
return core.GatewayTimeout(), core.NewLoggedError("Error while generating proxy response: %v", err)
return core.InternalServerError(), core.NewLoggedError("Error while generating proxy response: %v", err)
}

return proxyResponse, nil
Expand Down
4 changes: 2 additions & 2 deletions gorillamux/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ func New(router *mux.Router) *GorillaMuxAdapter {
func (h *GorillaMuxAdapter) Proxy(event events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
req, err := h.ProxyEventToHTTPRequest(event)
if err != nil {
return core.GatewayTimeout(), core.NewLoggedError("Could not convert proxy event to request: %v", err)
return core.InternalServerError(), core.NewLoggedError("Could not convert proxy event to request: %v", err)
}

w := core.NewProxyResponseWriter()
h.router.ServeHTTP(http.ResponseWriter(w), req)

resp, err := w.GetProxyResponse()
if err != nil {
return core.GatewayTimeout(), core.NewLoggedError("Error while generating proxy response: %v", err)
return core.InternalServerError(), core.NewLoggedError("Error while generating proxy response: %v", err)
}

return resp, nil
Expand Down
4 changes: 2 additions & 2 deletions handlerfunc/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ func New(handlerFunc http.HandlerFunc) *HandlerFuncAdapter {
func (h *HandlerFuncAdapter) Proxy(event events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
req, err := h.ProxyEventToHTTPRequest(event)
if err != nil {
return core.GatewayTimeout(), core.NewLoggedError("Could not convert proxy event to request: %v", err)
return core.InternalServerError(), core.NewLoggedError("Could not convert proxy event to request: %v", err)
}

w := core.NewProxyResponseWriter()
h.handlerFunc.ServeHTTP(http.ResponseWriter(w), req)

resp, err := w.GetProxyResponse()
if err != nil {
return core.GatewayTimeout(), core.NewLoggedError("Error while generating proxy response: %v", err)
return core.InternalServerError(), core.NewLoggedError("Error while generating proxy response: %v", err)
}

return resp, nil
Expand Down
4 changes: 2 additions & 2 deletions httpadapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ func New(handler http.Handler) *HandlerAdapter {
func (h *HandlerAdapter) Proxy(event events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
req, err := h.ProxyEventToHTTPRequest(event)
if err != nil {
return core.GatewayTimeout(), core.NewLoggedError("Could not convert proxy event to request: %v", err)
return core.InternalServerError(), core.NewLoggedError("Could not convert proxy event to request: %v", err)
}

w := core.NewProxyResponseWriter()
h.handler.ServeHTTP(http.ResponseWriter(w), req)

resp, err := w.GetProxyResponse()
if err != nil {
return core.GatewayTimeout(), core.NewLoggedError("Error while generating proxy response: %v", err)
return core.InternalServerError(), core.NewLoggedError("Error while generating proxy response: %v", err)
}

return resp, nil
Expand Down
4 changes: 2 additions & 2 deletions negroni/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ func New(n *negroni.Negroni) *NegroniAdapter {
func (h *NegroniAdapter) Proxy(event events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
req, err := h.ProxyEventToHTTPRequest(event)
if err != nil {
return core.GatewayTimeout(), core.NewLoggedError("Could not convert proxy event to request: %v", err)
return core.InternalServerError(), core.NewLoggedError("Could not convert proxy event to request: %v", err)
}

w := core.NewProxyResponseWriter()
h.n.ServeHTTP(http.ResponseWriter(w), req)

resp, err := w.GetProxyResponse()
if err != nil {
return core.GatewayTimeout(), core.NewLoggedError("Error while generating proxy response: %v", err)
return core.InternalServerError(), core.NewLoggedError("Error while generating proxy response: %v", err)
}

return resp, nil
Expand Down