Я пытаюсь попасть по URL-адресу
http://localhost:33250/api/v1/edit-order-request/?order_id=1231
, появляется эта ошибка:
invalid character 'R' looking for beginning of value
Что я делаю не так?
Изменить: http_client . go
func (c *HTTPClient) Call(url string, body interface{}, h http.Header, hc string, method string) (*response.BaseResponse, error) {
outputChannel := make(chan *response.BaseResponse, 1)
util.FilterHeaders(&h)
errChannel := hystrix.Go(hc, func() error {
var res *http.Response
var err error
switch method {
case util.Post:
rbyte, _ := json.Marshal(body)
rreader := bytes.NewReader(rbyte)
res, err = c.httpClient.Post(url, rreader, h)
case util.Put:
rbyte, _ := json.Marshal(body)
rreader := bytes.NewReader(rbyte)
res, err = c.httpClient.Put(url, rreader, h)
case util.Patch:
rbyte, _ := json.Marshal(body)
rreader := bytes.NewReader(rbyte)
res, err = c.httpClient.Patch(url, rreader, h)
case util.Get:
res, err = c.httpClient.Get(url, h)
log.Info().Msgf("res %v",res)
}
if err != nil {
log.Error().Err(err).Msgf(method+" api failed: %s", body)
return err
}
defer res.Body.Close()
var baseResponse response.BaseResponse
d := json.NewDecoder(res.Body)
d.UseNumber()
err = d.Decode(&baseResponse)
if err != nil {
log.Error().Err(err).Msgf("Failed to decode the response for url %s", url)
return err
}
baseResponse.HTTPStatusCode = res.StatusCode
outputChannel <- &baseResponse
return nil
}, func(err error) error {
return err
})
select {
case res := <-outputChannel:
log.Info().Msgf(method+" response for URL %s, BODY %s , HEADER %s, RESPONSE %s", url, util.ToJSON(body), util.ToJSON(h), util.ToJSON(res))
return res, nil
case err := <-errChannel:
log.Info().Msgf("Error received on error channel for URL %s", url)
return nil, err
}
}
Заглушка:
var EditServiceGetConversationIdOmtTaskIdNonEmptyStub = &wiremock.Stub{
Request: wiremock.Request{
Method: "GET",
UrlPattern: "/api/v1/edit-order-request/"+"?order_id=1231",
},
Response: wiremock.Response{
Status: 200,
Body: EditServiceGetConversationIdOmtTaskIdNonEmptyResponse,
},
}
var EditServiceGetConversationIdOmtTaskIdNonEmptyResponse = "{\"statusCode\":0,\"statusMessage\":\"success\",\"data\":{\"order_id\":1231,\"edit_reason\":\"EDIT\",\"crm_conversation_id\":\"p-qwr-1234\",\"omt_task_id\":\"1231\"}}"
Когда в заглушке я использую параметр Url, эта ошибка исчезает. Может ли кто-нибудь объяснить мне причину этого?
Журналы ошибок при использовании шаблона URL в качестве параметра:
http_client.go:54 > res &{404 Not Found 404 HTTP/1.1 1 1 map[Content-Type:[text/plain] Server:[Jetty(9.4.20.v20190813)]] 0xc001fd5200 -1 [] true false map[] 0xc0003e6100 <nil>}
http_client.go:66 > Failed to decode the response for url http://localhost:33350/api/v1/edit-order-request/?order_id=1231 error="invalid character 'R' looking for beginning of value"
http_client.go:81 > Error received on error channel for URL http://localhost:33350/api/v1/edit-order-request/?order_id=1231
Журналы успеха в случае использования URL в качестве параметра:
http_client.go:54 > res &{200 OK 200 HTTP/1.1 1 1 map[Matched-Stub-Id:[901cbfb1-fc1a-40e8-9f00-fae29f54be3d] Server:[Jetty(9.4.20.v20190813)] Vary:[Accept-Encoding, User-Agent]] 0xc0020aa8a0 -1 [] true true map[] 0xc0020a0600 <nil>}
http_client.go:78 > GET response for URL http://localhost:33355/api/v1/edit-order-request/?order_id=1231, BODY null , HEADER {"Authorization":["Basic R0dZU1dJOjIwMTVTVyFHR1k="],"Content-Type":["application/json"]}, RESPONSE {"statusCode":0,"statusMessage":"success","data":{"crm_conversation_id":"p-qwr-1234","edit_reason":"EDIT","omt_task_id":"1231","order_id":1231},"httpStatusCode":200,"id":0,"code":"","message":""}