Skip to content

Conversation

@kefahB
Copy link
Contributor

@kefahB kefahB commented Feb 17, 2020

Hi @EddyVerbruggen

There is inconsistency between AFSuccess and AFFailure on the response .. of course I understand it is not the same .. but when dealing with API REST we expecting to get sometimes status response like 301 or 422... the problem it is the AFFailure return the content in a new object content.body .. when trying to do some check stuff, we need a lot of change in our code to change response.content to response.content.body

I added a new objet failure instead of content and keeping content he same as AFSuccess.

let failure: any = {
    body: content,
    description: error.description,
    reason: error.localizedDescription,
    url: error.userInfo.objectForKey('NSErrorFailingURLKey').description
  };


  resolve({task, content, reason, failure: failure});

@kefahB kefahB changed the title Keeping response standard between AFSuccess and AFFailure [IOS] Keeping response standard between AFSuccess and AFFailure Feb 17, 2020
@kefahB
Copy link
Contributor Author

kefahB commented Feb 18, 2020

If you think that will affect the others .. we can add a new options :

{
    useLegacy: true // default (false) the AFFailure will return the "old" system, set to true to get the new retrun
}

// in AFFailure function add 
function AFFailure(resolve, reject, task: NSURLSessionDataTask, error: NSError) {
    // ... (code)
    if(this.opts.useLegacy) {
         let failure: any = {
            body: content,
            description: error.description,
            reason: error.localizedDescription,
            url: error.userInfo.objectForKey('NSErrorFailingURLKey').description
        };
        if (policies.secured === true) {
            failure.description = 'nativescript-https > Invalid SSL certificate! ' + error.description;
        }
        let reason = error.localizedDescription;
        resolve({task, content, reason, failure: failure});
    } else {
        let content: any = {
              body,
              description: error.description,
              reason: error.localizedDescription,
              url: error.userInfo.objectForKey('NSErrorFailingURLKey').description
        };

        if (policies.secured === true) {
           content.description = 'nativescript-https > Invalid SSL certificate! ' + content.description;
        }

        let reason = error.localizedDescription;
        resolve({task, content, reason});
   }
}

@kefahB
Copy link
Contributor Author

kefahB commented Mar 2, 2020

Hi @EddyVerbruggen .. what do you think about this PR ?

@kefahB
Copy link
Contributor Author

kefahB commented Apr 6, 2020

Hi @EddyVerbruggen,

I hope you have good health you and your family !

Any chance to view this please ?

@EddyVerbruggen EddyVerbruggen merged commit b1030ec into nativescript-community:master Apr 6, 2020
@EddyVerbruggen EddyVerbruggen added this to the 2.1.0 milestone Apr 7, 2020
@EddyVerbruggen
Copy link
Member

Sorry for the delay my man! All is well over here, hope you and your loved ones are safe too!

I've merged and published your PR (v 2.1.0).

All the best,
Eddy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants