ios - AFNetworking spits out an error, but how can I display it? -


i have app user can authenticate instapaper. need instapaper subscription able this, however, if try log in account isn't subscribed instapaper, want display error them.

but when try log in, afnetworking sees successful, displays error console:

error: error domain=afnetworkingerrordomain code=-1011 "expected status code in (200-299), got 400" userinfo=0x8374840 {nslocalizedrecoverysuggestion=[{"error_code": 1041, "message": "subscription account required", "type": "error"}], afnetworkingoperationfailingurlrequesterrorkey=https://www.instapaper.com/api/1/bookmarks/list>, nserrorfailingurlkey=https://www.instapaper.com/api/1/bookmarks/list, nslocalizeddescription=expected status code in (200-299), got 400, afnetworkingoperationfailingurlresponseerrorkey=}

all i'm using afxauthclient modification of afnetworking. subclassed create custom instapaper api client looks this:

#import "afinstapaperclient.h" #import "afjsonrequestoperation.h"  @implementation afinstapaperclient  + (afinstapaperclient *)sharedclient {     static afinstapaperclient *sharedclient = nil;     static dispatch_once_t oncetoken;     dispatch_once(&oncetoken, ^{         sharedclient = [[afinstapaperclient alloc] initwithbaseurl:[nsurl urlwithstring:@"https://www.instapaper.com/"]                                                    key:@"..."                                                    secret:@"..."];     });      return sharedclient; }  - (id)initwithbaseurl:(nsurl *)url {     if (self = [super initwithbaseurl:url]) {         [self registerhttpoperationclass:[afjsonrequestoperation class]];         [self setdefaultheader:@"accept" value:@"application/json"];     }      return self; }  @end 

and when log in, following code executed:

- (ibaction)donebuttonpressed:(uibarbuttonitem *)sender {            [[afinstapaperclient sharedclient] authorizeusingxauthwithaccesstokenpath:@"/api/1/oauth/access_token"                  accessmethod:@"post"                  username:self.loginbox.text                  password:self.passwordbox.text                  success:^(afxauthtoken *accesstoken) {                      // save token information keychain                      [uickeychainstore setstring:accesstoken.key forkey:@"instapaperkey"];                      [uickeychainstore setstring:accesstoken.secret forkey:@"instapapersecret"];                       uialertview *alert = [[uialertview alloc]                                            initwithtitle:@"login successful"                                            message:@"your articles being downloaded , appear in queue."                                            delegate:nil                                            cancelbuttontitle:@"ok"                                            otherbuttontitles: nil];                      [alert show];                       [[nsuserdefaults standarduserdefaults] setobject:@"yes" forkey:@"isloggedintoinstapaper"];                       [self dismissviewcontrolleranimated:yes completion:nil];                  }                  failure:^(nserror *error) {                                           uialertview *alert = [[uialertview alloc]                                            initwithtitle:@"login failed."                                            message:@"are connected internet? instapaper may down. try again later."                                            delegate:nil                                            cancelbuttontitle:@"okay"                                            otherbuttontitles: nil];                      [alert show];                  }]; } 

but code never goes failure block. how modify code allow me tell them need instapaper subscription account?

based on situation, don't think ever trigger failure block because request isn't failing. getting response web service. in experience failure block executes if fail response because of network availability or it.

therefore, need handle account error in success block. 1 way read status code returned in response. if status code 400 console showing alert user.

you can follow method used here "https://stackoverflow.com/q/8469492/2670912"


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -