mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-05 04:56:37 +08:00
merge: integrate media workflow fixes
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
const statusClientClosedRequest = 499
|
||||
|
||||
func requestContextCanceled(c *gin.Context, err error) bool {
|
||||
if errors.Is(err, context.Canceled) {
|
||||
return true
|
||||
}
|
||||
if c == nil || c.Request == nil {
|
||||
return false
|
||||
}
|
||||
return errors.Is(c.Request.Context().Err(), context.Canceled)
|
||||
}
|
||||
|
||||
func writeInternalOrCanceled(c *gin.Context, err error) {
|
||||
if requestContextCanceled(c, err) {
|
||||
c.AbortWithStatus(statusClientClosedRequest)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
}
|
||||
Reference in New Issue
Block a user