utils.go 700 B

12345678910111213141516171819202122232425262728
  1. package middleware
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "one-api/common"
  5. )
  6. func abortWithOpenAiMessage(c *gin.Context, statusCode int, message string) {
  7. userId := c.GetInt("id")
  8. c.JSON(statusCode, gin.H{
  9. "error": gin.H{
  10. "message": common.MessageWithRequestId(message, c.GetString(common.RequestIdKey), userId),
  11. "type": "new_api_error",
  12. },
  13. })
  14. c.Abort()
  15. common.LogError(c.Request.Context(), message)
  16. }
  17. func abortWithMidjourneyMessage(c *gin.Context, statusCode int, code int, description string) {
  18. c.JSON(statusCode, gin.H{
  19. "description": description,
  20. "type": "new_api_error",
  21. "code": code,
  22. })
  23. c.Abort()
  24. common.LogError(c.Request.Context(), description)
  25. }