remove status

This commit is contained in:
celogeek 2022-05-09 09:49:11 +02:00
parent 9934ef91c0
commit 41f4062d1b
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
5 changed files with 25 additions and 29 deletions

View File

@ -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,7 +97,6 @@ func (s *Service) Login(c *gin.Context) {
}
c.JSON(http.StatusOK, gin.H{
"status": "success",
"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() {

View File

@ -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()
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(),
})
err := c.Errors.Last()
if err == nil {
return
}
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,
})
}
}

View File

@ -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,
})
}

View File

@ -8,7 +8,6 @@ import (
func (s *Service) Me(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"status": "success",
"user": s.CurrentSession(c).Account.Login,
})
}

View File

@ -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,
})