Skip to content

Instantly share code, notes, and snippets.

@ammario
Created May 2, 2016 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ammario/f3621d310eba1a89210268e1584f7d67 to your computer and use it in GitHub Desktop.
Save ammario/f3621d310eba1a89210268e1584f7d67 to your computer and use it in GitHub Desktop.
Gin JSON API error
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