remove status
This commit is contained in:
parent
9934ef91c0
commit
41f4062d1b
@ -76,9 +76,7 @@ func (s *Service) Signup(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "success",
|
||||
})
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (s *Service) Login(c *gin.Context) {
|
||||
@ -99,8 +97,7 @@ func (s *Service) Login(c *gin.Context) {
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "success",
|
||||
"token": session.Token,
|
||||
"token": session.Token,
|
||||
})
|
||||
}
|
||||
|
||||
@ -114,9 +111,7 @@ func (s *Service) Logout(c *gin.Context) {
|
||||
c.AbortWithError(http.StatusNotFound, ErrSessionNotFound)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "success",
|
||||
})
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (s *Service) AccountInit() {
|
||||
|
@ -1,31 +1,37 @@
|
||||
package photosapi
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var (
|
||||
StatusSuccess = "success"
|
||||
StatusFailed = "failed"
|
||||
ErrReqMissingBody = errors.New("missing body")
|
||||
)
|
||||
|
||||
func (s *Service) HandleError(c *gin.Context) {
|
||||
c.Next()
|
||||
err := c.Errors.Last()
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.Errors.Last(); err != nil {
|
||||
if err.IsType(gin.ErrorTypeBind) {
|
||||
c.JSON(-1, gin.H{
|
||||
"status": StatusFailed,
|
||||
"error": "binding error",
|
||||
"details": strings.Split(err.Error(), "\n"),
|
||||
})
|
||||
} else {
|
||||
c.JSON(-1, gin.H{
|
||||
"status": StatusFailed,
|
||||
"error": err.Error(),
|
||||
})
|
||||
}
|
||||
details := err.Error()
|
||||
if details == "EOF" {
|
||||
details = "missing body"
|
||||
}
|
||||
|
||||
switch err.Type {
|
||||
case gin.ErrorTypeBind:
|
||||
c.JSON(-1, gin.H{
|
||||
"error": "binding error",
|
||||
"details": strings.Split(details, "\n"),
|
||||
})
|
||||
default:
|
||||
c.JSON(-1, gin.H{
|
||||
"error": details,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +141,6 @@ func (s *Service) FileCreate(c *gin.Context) {
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "success",
|
||||
"sum": file.Checksum,
|
||||
"nbChunks": len(file.Chunks),
|
||||
"size": rs,
|
||||
@ -163,7 +162,6 @@ func (s *Service) FileCreateChunk(c *gin.Context) {
|
||||
if err := chunk.Save(sess.Account.Login); err != nil {
|
||||
if errors.Is(err, ErrStoreChunkAlreadyExists) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "success",
|
||||
"checksum": chunk.Sum,
|
||||
})
|
||||
} else {
|
||||
@ -173,7 +171,6 @@ func (s *Service) FileCreateChunk(c *gin.Context) {
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "success",
|
||||
"checksum": chunk.Sum,
|
||||
})
|
||||
}
|
||||
|
@ -8,8 +8,7 @@ import (
|
||||
|
||||
func (s *Service) Me(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "success",
|
||||
"user": s.CurrentSession(c).Account.Login,
|
||||
"user": s.CurrentSession(c).Account.Login,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,6 @@ func (s *Service) Recovery(c *gin.Context) {
|
||||
if err := recover(); err != nil {
|
||||
s.LogErr.Print("PANIC", err)
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
|
||||
"status": StatusFailed,
|
||||
"error": ErrUnexpected.Error(),
|
||||
"details": err,
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user