Skip to content

Commit 836fdf9

Browse files
author
Mario de Frutos
committed
Added error func with custom code
1 parent 5888bc1 commit 836fdf9

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

context.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ func (c *Context) NoContent(code int) error {
8080
}
8181

8282
// Error invokes the registered HTTP error handler.
83-
func (c *Context) Error(err error, code int) {
83+
func (c *Context) Error(err error) {
84+
c.echo.httpErrorHandler(err, http.StatusInternalServerError, c)
85+
}
86+
87+
// Error invokes the registered HTTP error handler.
88+
// with a custom code
89+
func (c *Context) ErrorWithCode(err error, code int) {
8490
c.echo.httpErrorHandler(err, code, c)
8591
}
8692

middleware/logger.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package middleware
22

33
import (
44
"log"
5-
"net/http"
65
"time"
76

87
"github.com/labstack/echo"
@@ -13,7 +12,7 @@ func Logger(h echo.HandlerFunc) echo.HandlerFunc {
1312
return func(c *echo.Context) error {
1413
start := time.Now()
1514
if err := h(c); err != nil {
16-
c.Error(err, http.StatusInternalServerError)
15+
c.Error(err)
1716
}
1817
end := time.Now()
1918
m := c.Request.Method

0 commit comments

Comments
 (0)