whatsapp-multi-devicewhatsapp-apiwhatsapprestgolanggobotwhatsapp-web-multi-devicewhatsapp-api-gorest-apigolang-whatsapp-apigolang-whatsapp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
771 B
33 lines
771 B
package middleware
|
|
|
|
import (
|
|
"fmt"
|
|
pkgError "github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/error"
|
|
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func Recovery() fiber.Handler {
|
|
return func(ctx *fiber.Ctx) error {
|
|
defer func() {
|
|
err := recover()
|
|
if err != nil {
|
|
var res utils.ResponseData
|
|
res.Status = 500
|
|
res.Code = "INTERNAL_SERVER_ERROR"
|
|
res.Message = fmt.Sprintf("%v", err)
|
|
|
|
errValidation, isValidationError := err.(pkgError.GenericError)
|
|
if isValidationError {
|
|
res.Status = errValidation.StatusCode()
|
|
res.Code = errValidation.ErrCode()
|
|
res.Message = errValidation.Error()
|
|
}
|
|
|
|
_ = ctx.Status(res.Status).JSON(res)
|
|
}
|
|
}()
|
|
|
|
return ctx.Next()
|
|
}
|
|
}
|