diff options
author | Wolfy-J <[email protected]> | 2018-07-08 21:01:19 -0700 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-07-08 21:01:19 -0700 |
commit | a180d5e1128f735976497dff69c8c3a1061c42c7 (patch) | |
tree | 11540a1f3005f688f91125f80309afc7fec83b63 /service | |
parent | 89fe2046ce3b2c22188d731d00db4917fc77d834 (diff) |
better debugging
Diffstat (limited to 'service')
-rw-r--r-- | service/http/handler.go | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/service/http/handler.go b/service/http/handler.go index 6f2617b1..9e67e5b4 100644 --- a/service/http/handler.go +++ b/service/http/handler.go @@ -9,26 +9,29 @@ import ( ) const ( - // EventResponse thrown after the request been processed. See Event as payload. + // EventResponse thrown after the request been processed. See ErrorEvent as payload. EventResponse = iota + 500 // EventError thrown on any non job error provided by road runner server. EventError ) -// Event represents singular http response event. -type Event struct { - // Method of the request. - Method string +// ErrorEvent represents singular http error event. +type ErrorEvent struct { + // Request contains client request, must not be stored. + Request *http.Request - // URI requested by the client. - URI string + // Error - associated error, if any. + Error error +} - // Status is response status. - Status int +// ResponseEvent represents singular http response event. +type ResponseEvent struct { + // Request contains client request, must not be stored. + Request *Request - // Associated error, if any. - Error error + // Response contains service response. + Response *Response } // Handler serves http connections to underlying PHP application using PSR-7 protocol. Context will include request headers, @@ -99,7 +102,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // handleError sends error. func (h *Handler) handleError(w http.ResponseWriter, r *http.Request, err error) { - h.throw(EventError, &Event{Method: r.Method, URI: uri(r), Status: 500, Error: err}) + h.throw(EventError, &ErrorEvent{Request: r, Error: err}) w.WriteHeader(500) w.Write([]byte(err.Error())) @@ -107,7 +110,7 @@ func (h *Handler) handleError(w http.ResponseWriter, r *http.Request, err error) // handleResponse triggers response event. func (h *Handler) handleResponse(req *Request, resp *Response) { - h.throw(EventResponse, &Event{Method: req.Method, URI: req.URI, Status: resp.Status}) + h.throw(EventResponse, &ResponseEvent{Request: req, Response: resp}) } // throw invokes event srv if any. |