Created
May 2, 2016 18:44
-
-
Save ammario/f3621d310eba1a89210268e1584f7d67 to your computer and use it in GitHub Desktop.
Gin JSON API error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func cError(c *gin.Context, err interface{}) { | |
switch err.(type) { | |
case error: | |
c.JSON(200, gin.H{ | |
"error": err.(error).Error(), | |
}) | |
case string: | |
c.JSON(200, gin.H{ | |
"error": err.(string), | |
}) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment