summaryrefslogtreecommitdiffstats
path: root/golib/error.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-06-26 17:58:36 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-06-26 17:58:36 +0200
commit1e628d0aaaa9137efa52d05351083abf05f97106 (patch)
tree5ef5ea99f3686f40129aadfe697f97ec7a093d0d /golib/error.go
parent3348095d2b00947f23f20237377a52d4c5949b6b (diff)
Initial commit to add golib
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'golib/error.go')
-rw-r--r--golib/error.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/golib/error.go b/golib/error.go
new file mode 100644
index 0000000..6873d82
--- /dev/null
+++ b/golib/error.go
@@ -0,0 +1,16 @@
+package common
+
+import (
+ "fmt"
+
+ "github.com/gin-gonic/gin"
+)
+
+// APIError returns an uniform json formatted error
+func APIError(c *gin.Context, format string, args ...interface{}) {
+ errMsg := fmt.Sprintf(format, args...)
+ c.JSON(500, gin.H{
+ "status": "error",
+ "error": errMsg,
+ })
+}