|
|
@@ -179,15 +179,24 @@ func Relay(c *gin.Context, relayFormat types.RelayFormat) {
|
|
|
}
|
|
|
|
|
|
for ; retryParam.GetRetry() <= common.RetryTimes; retryParam.IncreaseRetry() {
|
|
|
- channel, err := getChannel(c, relayInfo, retryParam)
|
|
|
- if err != nil {
|
|
|
- logger.LogError(c, err.Error())
|
|
|
- newAPIError = err
|
|
|
+ channel, channelErr := getChannel(c, relayInfo, retryParam)
|
|
|
+ if channelErr != nil {
|
|
|
+ logger.LogError(c, channelErr.Error())
|
|
|
+ newAPIError = channelErr
|
|
|
break
|
|
|
}
|
|
|
|
|
|
addUsedChannel(c, channel.Id)
|
|
|
- requestBody, _ := common.GetRequestBody(c)
|
|
|
+ requestBody, bodyErr := common.GetRequestBody(c)
|
|
|
+ if bodyErr != nil {
|
|
|
+ // Ensure consistent 413 for oversized bodies even when error occurs later (e.g., retry path)
|
|
|
+ if common.IsRequestBodyTooLargeError(bodyErr) || errors.Is(bodyErr, common.ErrRequestBodyTooLarge) {
|
|
|
+ newAPIError = types.NewErrorWithStatusCode(bodyErr, types.ErrorCodeReadRequestBodyFailed, http.StatusRequestEntityTooLarge, types.ErrOptionWithSkipRetry())
|
|
|
+ } else {
|
|
|
+ newAPIError = types.NewErrorWithStatusCode(bodyErr, types.ErrorCodeReadRequestBodyFailed, http.StatusBadRequest, types.ErrOptionWithSkipRetry())
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody))
|
|
|
|
|
|
switch relayFormat {
|
|
|
@@ -473,7 +482,15 @@ func RelayTask(c *gin.Context) {
|
|
|
logger.LogInfo(c, fmt.Sprintf("using channel #%d to retry (remain times %d)", channel.Id, retryParam.GetRetry()))
|
|
|
//middleware.SetupContextForSelectedChannel(c, channel, originalModel)
|
|
|
|
|
|
- requestBody, _ := common.GetRequestBody(c)
|
|
|
+ requestBody, err := common.GetRequestBody(c)
|
|
|
+ if err != nil {
|
|
|
+ if common.IsRequestBodyTooLargeError(err) || errors.Is(err, common.ErrRequestBodyTooLarge) {
|
|
|
+ taskErr = service.TaskErrorWrapperLocal(err, "read_request_body_failed", http.StatusRequestEntityTooLarge)
|
|
|
+ } else {
|
|
|
+ taskErr = service.TaskErrorWrapperLocal(err, "read_request_body_failed", http.StatusBadRequest)
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody))
|
|
|
taskErr = taskRelayHandler(c, relayInfo)
|
|
|
}
|