Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error code for every particular error in a particular domain #42

Closed
tikhop opened this issue Nov 7, 2013 · 11 comments
Closed

Add error code for every particular error in a particular domain #42

tikhop opened this issue Nov 7, 2013 · 11 comments
Assignees

Comments

@tikhop
Copy link

tikhop commented Nov 7, 2013

It will be useful if you need a special action after error handling.

@nst
Copy link
Owner

nst commented Nov 7, 2013

I'm not sure I understand your request. Could you please elaborate or give an example? Thank you in advance.

@tikhop
Copy link
Author

tikhop commented Nov 7, 2013

So, for example, take STTwitterOS implementation, scroll down to line #85.

Here you create an error and pass a code equal to '0':

- (void)verifyCredentialsWithSuccessBlock:(void(^)(NSString *username))successBlock errorBlock:(void(^)(NSError *error))errorBlock {
    if([self hasAccessToTwitter] == NO) {
        NSString *message = @"This system cannot access Twitter.";
        NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:0 userInfo:@{NSLocalizedDescriptionKey : message}];
        errorBlock(error);
        return;
    }
    ....
}

Idea is to create a special error code for every particular error in a particular domain.

You can define enum for every particular domain or one for the entire project:

typedef NS_ENUM(NSUInteger, STTwitterOSErrorCode) {
    STTwitterOSErrorCodeCannotAccessTwitter, //This system cannot access Twitter.
        //etc
};

And later you use a code with error and client, who received that error can be used to compare that code.

...
//Sending error
 NSString *message = @"This system cannot access Twitter.";
        NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:STTwitterOSErrorCodeCannotAccessTwitter userInfo:@{NSLocalizedDescriptionKey : message}];
errorBlock(error);
...

...
//Handling error
 [_twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {

        _loginStatusLabel.text = username;

    } errorBlock:^(NSError *error) {
        if(error.code == STTwitterOSErrorCodeCannotAccessTwitter) {
                //Do something special
        }

}];

@nst
Copy link
Owner

nst commented Nov 7, 2013

Thank you for this explanation. You're totally right. I'll add errors soon.

@ghost ghost assigned nst Nov 7, 2013
@tikhop
Copy link
Author

tikhop commented Nov 7, 2013

You are welcome, thanks for understanding.

nst added a commit that referenced this issue Nov 8, 2013
@nst
Copy link
Owner

nst commented Nov 8, 2013

41c9df9

@nst nst closed this as completed Nov 8, 2013
@Arsalan90
Copy link

Hello can you plz help me I'm using STTwitter and using this method for reverse authentication but i'm getting error like this

Error Domain=STTwitterOS Code=0 "This system cannot access Twitter." UserInfo=0xd8f05b0 {NSLocalizedDescription=This system cannot access Twitter.

here what I'm using

  STTwitterAPI *twitter  = [STTwitterAPI twitterAPIWithOAuthConsumerKey:TWITTER_CONSUMER_KEY
                                                           consumerSecret:TWITTER_CONSUMER_SECRET];
[twitter postReverseOAuthTokenRequest:^(NSString *authenticationHeader) {

        STTwitterAPI *twitterAPIOS = [STTwitterAPI twitterAPIOSWithFirstAccount];

      [twitterAPIOS verifyCredentialsWithSuccessBlock:^(NSString *username) {

          [twitterAPIOS postReverseAuthAccessTokenWithAuthenticationHeader:authenticationHeader
                                                               successBlock:^(NSString *oAuthToken,
                                                                            NSString *oAuthTokenSecret,
                                                                              NSString *userID,
                                                                              NSString *screenName) {
                                                                    NSLog(@"oAuthToken: %@, oAuthTokenSecret: %@, userID: %@, screenName: %@", oAuthToken, oAuthTokenSecret, userID, screenName);

                                                                   self.twAuthData = @{@"oAuthToken" : oAuthToken,
                                                                                      @"oAuthTokenSecret" : oAuthTokenSecret,
                                                                                       @"userID" : userID,
                                                                                       @"screenName" : screenName};
                                                                   if ([self.twDelegate respondsToSelector:@selector(loginForNetwork:successful:needsRegistration:)]) {
                                                                        [self.twDelegate loginForNetwork:kNetworkType_TW successful:YES needsRegistration:YES];

}
          } errorBlock:^(NSError *error) {
              NSLog(@"error %@", error);
        }];

       } errorBlock:^(NSError *error) {
           NSLog(@"error %@", error);
             }];

   } errorBlock:^(NSError *error) {
       NSLog(@"error %@", error);
   }];

need your help

@nst
Copy link
Owner

nst commented Aug 6, 2014

Are you sure there is a Twitter account set up in iOS Settings? (or OS X Preferences if you're on OS X)

@SravaniPavuluri
Copy link

Hi,
I am getting this error ERror: Error Domain=STTwitterTwitterErrorDomain Code=0 "not recognized." UserInfo=0x7b0c8d90 {NSLocalizedDescription=not recognized.} when I am trying to upload video.
I got Twitter account from my device settings.
Here is my code to upload video:

[_twitter postMediaUploadData:[NSData dataWithContentsOfFile:filePath] fileName:@"Test" uploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
} successBlock:^(NSDictionary *imageDictionary, NSString *mediaID, NSString *size) {
NSLog(@"Image dictionary: %@", imageDictionary);
NSLog(@"Media ID; %@", mediaID);
NSLog(@"Size; %@", size);
} errorBlock:^(NSError *error) {
NSLog(@"ERror: %@",error);
}];
I am not sure if I am in correct path or not. Please let me know if anything wrong.

Thanks in Advance :)

@nst
Copy link
Owner

nst commented Oct 29, 2014

From Twitter API documentation: "Currently, the only type exposed in our entities is photo". So I don't think you can upload videos.

@userIOS
Copy link

userIOS commented Nov 14, 2014

Hi, I need your help. I'm trying different solutions for days :(

I sign in into twitter in my app, I have the authorization. And everything is OK. In that moment I save oAuthToken, oAuthTokenSecret, username... and all the info that I can with the purpose of don't ask again user for his username/password.

So the next time that user go into the app, I just want to post with the twitter's info that I have saved. But I can't "reconnect" or "reopen" the session.

Please, could anyone help me?? I'm really struggling :/

This is what I'm trying:

STTwitterAPI *twitter = [STTwitterAPI twitterAPIWithOAuthConsumerName:nil
consumerKey:@"xxx"
consumerSecret:@"xxx"];

    [twitter postReverseOAuthTokenRequest:^(NSString *authenticationHeader) {

        STTwitterAPI *twitterAPIOS = [STTwitterAPI twitterAPIOSWithFirstAccount];

        [twitterAPIOS verifyCredentialsWithSuccessBlock:^(NSString *username) {

            [twitterAPIOS postReverseAuthAccessTokenWithAuthenticationHeader:authenticationHeader
                                                                successBlock:^(NSString *oAuthToken,
                                                                               NSString *oAuthTokenSecret,
                                                                               NSString *userID,
                                                                               NSString *screenName) {

                                                                    // I'm trying to POST on twitter HERE

        } errorBlock:^(NSError *error) {
             NSLog(@"-- ERROR1: %@", error);
        }];

    } errorBlock:^(NSError *error) {
         NSLog(@"-- ERROR2: %@", error);
    }];

And the ERROR that I'm getting is the first one that I control:

ERROR1: Error Domain=STTwitterOS Code=0 "This system cannot access Twitter." UserInfo=0x14d06d30 {NSLocalizedDescription=This system cannot access Twitter.}

@userIOS
Copy link

userIOS commented Nov 14, 2014

Well, I think that the wrong point is when I ask for twitterAPIOSWithFirstAccount. Because I haven't got twitter installed in my phone. So, How could I create an account from the saved info that I have of the first user's authentication??

Thank you in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants