infinitered / apisauce

Axios + standardized errors + request/response transforms.
MIT License
2.8k stars 184 forks source link

send content type in get request fail in IOS #266

Closed xforcarlos closed 3 years ago

xforcarlos commented 3 years ago

What's going on? working on Project depending on JsonApi

spend content type in get request fail on iOS work fine on android

Steps to reproduce

jsonapi standard in get request need a Content-type example : headers: { "Content-Type": "application/vnd.api+json", Accept: "application/vnd.api+json", }, to make apisauce send content-type in get request i send and empty obj data like const response : ApiResponse = await this.apisauce.get("/example", {}, { data: {} })


results results:

on android
config:
adapter: ƒ xhrAdapter(config)
baseURL: "www.example.com"
data: "{}"
headers:
Accept: "application/vnd.api+json"
Authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODAwM1wvYXBpXC92MVwvYXJcL2xvZ2luIiwiaWF0IjoxNjI2MDI5ODg1LCJleHAiOjE2Mjg2MjE4ODUsIm5iZiI6MTYyNjAyOTg4NSwianRpIjoidUhtWEM3dldNM3Zpb2NScSIsInN1YiI6IjFiYzM4Yzg0LTljYmYtNDViYi04NWRmLWUzNzlhOTQwYTYwYSIsInBydiI6ImVlOTcyZWU0NDg1NjFjMTJlZjRjOGRmMTMyMjE1ODI5YmU1NDgyODcifQ.4es9uvCbl7DANNw7fWDf_IkaX2i1wrBzYvNTL3TqTV4"
Content-Type: "application/vnd.api+json"
__proto__: Object
maxBodyLength: -1
maxContentLength: -1
method: "get"
params: {}
timeout: 30000
transformRequest: [ƒ]
transformResponse: [ƒ]
url: ""
validateStatus: ƒ validateStatus(status)
xsrfCookieName: "XSRF-TOKEN"
xsrfHeaderName: "X-XSRF-TOKEN"
__proto__: Object
data: {data: Array(0), meta: {…}, links: {…}}
duration: 1882
headers:
access-control-allow-origin: "*"
cache-control: "private, must-revalidate"
connection: "keep-alive"
content-type: "text/html; charset=UTF-8"
date: "Sun, 11 Jul 2021 18:58:07 GMT"
expires: "-1"
pragma: "no-cache"
server: "nginx/1.18.0 (Ubuntu)"
transfer-encoding: "chunked"
x-powered-by: "PHP/7.4.16"
x-ratelimit-limit: "60"
x-ratelimit-remaining: "58"
__proto__: Object
ok: true
originalError: null
problem: null
status: 200

**************************************************************************************************

iOS 
the error here...
config: Object
adapter: ƒ ()
baseURL: "www.example.com"
data: "{}"
headers: Object
Accept: "application/vnd.api+json"
Authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODAwM1wvYXBpXC92MVwvYXJcL2xvZ2luIiwiaWF0IjoxNjI2MDI0NTI2LCJleHAiOjE2Mjg2MTY1MjYsIm5iZiI6MTYyNjAyNDUyNiwianRpIjoianREa2toRmZ1SXRpRnRBZiIsInN1YiI6IjFiYzM4Yzg0LTljYmYtNDViYi04NWRmLWUzNzlhOTQwYTYwYSIsInBydiI6ImVlOTcyZWU0NDg1NjFjMTJlZjRjOGRmMTMyMjE1ODI5YmU1NDgyODcifQ.S4qvtR_gX4cy5LE7D6s3My_hIyYcOaV6lxumI6x3Ulc"
Content-Type: "application/vnd.api+json"
__proto__: Object
maxBodyLength: -1
maxContentLength: -1
method: "get"
params: Object
__proto__: Object
constructor: ƒ ()
hasOwnProperty: ƒ ()
isPrototypeOf: ƒ ()
propertyIsEnumerable: ƒ ()
toLocaleString: ƒ ()
toString: ƒ ()
valueOf: ƒ ()
__defineGetter__: ƒ ()
__defineSetter__: ƒ ()
__lookupGetter__: ƒ ()
__lookupSetter__: ƒ ()
__proto__: null
timeout: 30000
transformRequest: Array(1)
transformResponse: Array(1)
url: ""
validateStatus: ƒ ()
xsrfCookieName: "XSRF-TOKEN"
xsrfHeaderName: "X-XSRF-TOKEN"
__proto__: Object
data: null
duration: 2372
headers: null
ok: false
originalError: Object
problem: "NETWORK_ERROR"
status: null
chakrihacker commented 3 years ago

From the results you shared above I can see Content-Type: "application/vnd.api+json" on iOS can you share more info about the error?

meldawi commented 3 years ago

Hi @chakrihacker
I already shared all the info that you'll need. Are you looking for files in particular? and Ignite doctor

  node                14.17.0      /usr/local/opt/node@14/bin/node 
  npm                 6.14.13      /usr/local/opt/node@14/bin/npm  
    axios             0.21.1                                       
    detox-cli         18.0.0                                       
    ignite-cli        6.6.0                                        
    ios-deploy        1.11.3                                       
    npm               6.14.13                                      
    osmi-cli          1.2.0                                        
    pod-install       0.1.18                                       
    react-devtools    4.10.4                                       
  yarn                1.22.10      /usr/local/bin/yarn             
    create-next-app   11.0.0                                       

Ignite
  ignite-cli         6.6.0        /usr/local/bin/ignite                        
  ignite src         build        /usr/local/lib/node_modules/ignite-cli/build 

Android
  java               1.8.0_282    /usr/bin/java                           
  android home       -            /Users/mahmoudhamdy/Library/Android/sdk 

iOS
  xcode              12.5.1     
  cocoapods          1.10.1       /usr/local/bin/pod 

app package.json

    "react": "17.0.1",
    "react-native": "0.64.2",
    "apisauce": "2.0.0",
    "axios": "^0.18.0",

ios =>. 14.5

please let me know if you need more info

xforcarlos commented 3 years ago

@chakrihacker hey man i found solution

 this.apisauce.axiosInstance.interceptors.request.use((config) => {
      if (config.method == "get") {
        config.data = null
      }

to make apisauce send content-type i get request make data with null

chakrihacker commented 3 years ago

I am glad you found a solution, closing this issue