chore: add id to resp of create storage
This commit is contained in:
@ -21,6 +21,23 @@ func hidePrivacy(msg string) string {
|
||||
// ErrorResp is used to return error response
|
||||
// @param l: if true, log error
|
||||
func ErrorResp(c *gin.Context, err error, code int, l ...bool) {
|
||||
ErrorWithDataResp(c, err, code, nil, l...)
|
||||
//if len(l) > 0 && l[0] {
|
||||
// if flags.Debug || flags.Dev {
|
||||
// log.Errorf("%+v", err)
|
||||
// } else {
|
||||
// log.Errorf("%v", err)
|
||||
// }
|
||||
//}
|
||||
//c.JSON(200, Resp[interface{}]{
|
||||
// Code: code,
|
||||
// Message: hidePrivacy(err.Error()),
|
||||
// Data: nil,
|
||||
//})
|
||||
//c.Abort()
|
||||
}
|
||||
|
||||
func ErrorWithDataResp(c *gin.Context, err error, code int, data interface{}, l ...bool) {
|
||||
if len(l) > 0 && l[0] {
|
||||
if flags.Debug || flags.Dev {
|
||||
log.Errorf("%+v", err)
|
||||
@ -31,7 +48,7 @@ func ErrorResp(c *gin.Context, err error, code int, l ...bool) {
|
||||
c.JSON(200, Resp[interface{}]{
|
||||
Code: code,
|
||||
Message: hidePrivacy(err.Error()),
|
||||
Data: nil,
|
||||
Data: data,
|
||||
})
|
||||
c.Abort()
|
||||
}
|
||||
|
@ -36,10 +36,14 @@ func CreateStorage(c *gin.Context) {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
if err := op.CreateStorage(c, req); err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
if id, err := op.CreateStorage(c, req); err != nil {
|
||||
common.ErrorWithDataResp(c, err, 500, gin.H{
|
||||
"id": id,
|
||||
}, true)
|
||||
} else {
|
||||
common.SuccessResp(c)
|
||||
common.SuccessResp(c, gin.H{
|
||||
"id": id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user