|
@@ -158,16 +158,19 @@ func DoMidjourneyHttpRequest(c *gin.Context, timeout time.Duration, fullRequestU
|
|
|
//requestBody = c.Request.Body
|
|
//requestBody = c.Request.Body
|
|
|
// read request body to json, delete accountFilter and notifyHook
|
|
// read request body to json, delete accountFilter and notifyHook
|
|
|
var mapResult map[string]interface{}
|
|
var mapResult map[string]interface{}
|
|
|
- err := json.NewDecoder(c.Request.Body).Decode(&mapResult)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "read_request_body_failed", http.StatusInternalServerError), nullBytes, err
|
|
|
|
|
- }
|
|
|
|
|
- delete(mapResult, "accountFilter")
|
|
|
|
|
- if !constant.MjNotifyEnabled {
|
|
|
|
|
- delete(mapResult, "notifyHook")
|
|
|
|
|
|
|
+ // if get request, no need to read request body
|
|
|
|
|
+ if c.Request.Method != "GET" {
|
|
|
|
|
+ err := json.NewDecoder(c.Request.Body).Decode(&mapResult)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "read_request_body_failed", http.StatusInternalServerError), nullBytes, err
|
|
|
|
|
+ }
|
|
|
|
|
+ delete(mapResult, "accountFilter")
|
|
|
|
|
+ if !constant.MjNotifyEnabled {
|
|
|
|
|
+ delete(mapResult, "notifyHook")
|
|
|
|
|
+ }
|
|
|
|
|
+ //req, err := http.NewRequest(c.Request.Method, fullRequestURL, requestBody)
|
|
|
|
|
+ // make new request with mapResult
|
|
|
}
|
|
}
|
|
|
- //req, err := http.NewRequest(c.Request.Method, fullRequestURL, requestBody)
|
|
|
|
|
- // make new request with mapResult
|
|
|
|
|
reqBody, err := json.Marshal(mapResult)
|
|
reqBody, err := json.Marshal(mapResult)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "marshal_request_body_failed", http.StatusInternalServerError), nullBytes, err
|
|
return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "marshal_request_body_failed", http.StatusInternalServerError), nullBytes, err
|
|
@@ -209,11 +212,15 @@ func DoMidjourneyHttpRequest(c *gin.Context, timeout time.Duration, fullRequestU
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "close_response_body_failed", statusCode), responseBody, err
|
|
return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "close_response_body_failed", statusCode), responseBody, err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- err = json.Unmarshal(responseBody, &midjResponse)
|
|
|
|
|
- log.Printf("responseBody: %s", string(responseBody))
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "unmarshal_response_body_failed", statusCode), responseBody, err
|
|
|
|
|
|
|
+ respStr := string(responseBody)
|
|
|
|
|
+ log.Printf("responseBody: %s", respStr)
|
|
|
|
|
+ if respStr == "" {
|
|
|
|
|
+ return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "empty_response_body", statusCode), responseBody, nil
|
|
|
|
|
+ } else {
|
|
|
|
|
+ err = json.Unmarshal(responseBody, &midjResponse)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "unmarshal_response_body_failed", statusCode), responseBody, err
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
//log.Printf("midjResponse: %v", midjResponse)
|
|
//log.Printf("midjResponse: %v", midjResponse)
|
|
|
//for k, v := range resp.Header {
|
|
//for k, v := range resp.Header {
|