Skip to content

Instantly share code, notes, and snippets.

Last active Aug 4, 2017
What would you like to do?
package app_error
import (
type ApiError struct {
StatusCode int `json:"status_code"`
Type string `json:"type"`
ResponsedAt string `json:"responsed_at"` // RFC3339
Message string `json:"message"`
UserMessageTitle string `json:"user_message_title"`
UserMessages []string `json:"user_messages"`
Tip string `json:"tip"`
func CustomHTTPErrorHandler(err error, c echo.Context) {
code := http.StatusInternalServerError
message := ""
if ee, ok := err.(*echo.HTTPError); ok {
code = ee.Code
message = ee.Message.(string)
body := ApiError{
StatusCode: code,
Type: "echo_error",
ResponsedAt: time.Now().Format(time.RFC3339),
Message: message,
UserMessageTitle: "",
UserMessages: []string{},
Tip: "",
c.JSON(code, body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment