mirror of
https://github.com/tgdrive/teldrive.git
synced 2024-11-10 17:14:03 +08:00
23 lines
419 B
Go
23 lines
419 B
Go
package httputil
|
|
|
|
import (
|
|
"github.com/divyam234/teldrive/pkg/logging"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func NewError(ctx *gin.Context, status int, err error) {
|
|
logger := logging.FromContext(ctx)
|
|
logger.Error(err)
|
|
if status == 0 {
|
|
status = 500
|
|
}
|
|
ctx.JSON(status, HTTPError{
|
|
Code: status,
|
|
Message: err.Error(),
|
|
})
|
|
}
|
|
|
|
type HTTPError struct {
|
|
Code int `json:"code"`
|
|
Message string `json:"message"`
|
|
}
|