52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
|
package processor
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"net/http"
|
||
|
|
||
|
"git.optclblast.xyz/draincloud/draincloud-core/internal/common"
|
||
|
"git.optclblast.xyz/draincloud/draincloud-core/internal/domain"
|
||
|
"git.optclblast.xyz/draincloud/draincloud-core/internal/errs"
|
||
|
"git.optclblast.xyz/draincloud/draincloud-core/internal/handler"
|
||
|
"git.optclblast.xyz/draincloud/draincloud-core/internal/storage"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
type Processor struct {
|
||
|
rp *common.RequestPool
|
||
|
authStorage storage.AuthStorage
|
||
|
}
|
||
|
|
||
|
func (p *Processor) Process(handler *handler.Handler) gin.HandlerFunc {
|
||
|
return func(ctx *gin.Context) {
|
||
|
//req := common.NewRequest(p.rp, ctx.Request)
|
||
|
// if handler.WithAuth {
|
||
|
// if err := p.authorize(ctx, req); err != nil {
|
||
|
// p.writeError(ctx, err)
|
||
|
// return
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (p *Processor) writeError(ctx *gin.Context, err error) {
|
||
|
switch {
|
||
|
case errors.Is(err, errs.ErrorAccessDenied):
|
||
|
ctx.JSON(http.StatusInternalServerError, domain.ErrorJson{
|
||
|
Code: http.StatusForbidden,
|
||
|
Message: err.Error(),
|
||
|
})
|
||
|
case errors.Is(err, errs.ErrorSessionExpired):
|
||
|
ctx.JSON(http.StatusInternalServerError, domain.ErrorJson{
|
||
|
Code: http.StatusForbidden,
|
||
|
Message: err.Error(),
|
||
|
})
|
||
|
default:
|
||
|
ctx.JSON(http.StatusInternalServerError, domain.ErrorJson{
|
||
|
Code: http.StatusInternalServerError,
|
||
|
Message: "Internal Error",
|
||
|
})
|
||
|
}
|
||
|
}
|