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 return
} }
c.JSON(http.StatusOK, gin.H{ c.Status(http.StatusNoContent)
"status": "success",
})
} }
func (s *Service) Login(c *gin.Context) { func (s *Service) Login(c *gin.Context) {
@ -99,8 +97,7 @@ func (s *Service) Login(c *gin.Context) {
} }
c.JSON(http.StatusOK, gin.H{ 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) c.AbortWithError(http.StatusNotFound, ErrSessionNotFound)
return return
} }
c.JSON(http.StatusOK, gin.H{ c.Status(http.StatusNoContent)
"status": "success",
})
} }
func (s *Service) AccountInit() { func (s *Service) AccountInit() {

View File

@ -1,31 +1,37 @@
package photosapi package photosapi
import ( import (
"errors"
"strings" "strings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
var ( var (
StatusSuccess = "success" ErrReqMissingBody = errors.New("missing body")
StatusFailed = "failed"
) )
func (s *Service) HandleError(c *gin.Context) { func (s *Service) HandleError(c *gin.Context) {
c.Next() c.Next()
err := c.Errors.Last()
if err == nil {
return
}
if err := c.Errors.Last(); err != nil { details := err.Error()
if err.IsType(gin.ErrorTypeBind) { if details == "EOF" {
c.JSON(-1, gin.H{ details = "missing body"
"status": StatusFailed, }
"error": "binding error",
"details": strings.Split(err.Error(), "\n"), switch err.Type {
}) case gin.ErrorTypeBind:
} else { c.JSON(-1, gin.H{
c.JSON(-1, gin.H{ "error": "binding error",
"status": StatusFailed, "details": strings.Split(details, "\n"),
"error": err.Error(), })
}) 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{ c.JSON(http.StatusOK, gin.H{
"status": "success",
"sum": file.Checksum, "sum": file.Checksum,
"nbChunks": len(file.Chunks), "nbChunks": len(file.Chunks),
"size": rs, "size": rs,
@ -163,7 +162,6 @@ func (s *Service) FileCreateChunk(c *gin.Context) {
if err := chunk.Save(sess.Account.Login); err != nil { if err := chunk.Save(sess.Account.Login); err != nil {
if errors.Is(err, ErrStoreChunkAlreadyExists) { if errors.Is(err, ErrStoreChunkAlreadyExists) {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"status": "success",
"checksum": chunk.Sum, "checksum": chunk.Sum,
}) })
} else { } else {
@ -173,7 +171,6 @@ func (s *Service) FileCreateChunk(c *gin.Context) {
} }
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"status": "success",
"checksum": chunk.Sum, "checksum": chunk.Sum,
}) })
} }

View File

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

View File

@ -18,7 +18,6 @@ func (s *Service) Recovery(c *gin.Context) {
if err := recover(); err != nil { if err := recover(); err != nil {
s.LogErr.Print("PANIC", err) s.LogErr.Print("PANIC", err)
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{ c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
"status": StatusFailed,
"error": ErrUnexpected.Error(), "error": ErrUnexpected.Error(),
"details": err, "details": err,
}) })