Skip to content

Commit

Permalink
added some error codes, fix issue #42
Browse files Browse the repository at this point in the history
  • Loading branch information
nst committed Nov 8, 2013
1 parent 05321d3 commit 41c9df9
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 10 deletions.
5 changes: 5 additions & 0 deletions STTwitter/STTwitterAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

#import <Foundation/Foundation.h>

NS_ENUM(NSUInteger, STTwitterAPIErrorCode) {
STTwitterAPICannotPostEmptyStatus,
STTwitterAPIMediaDataIsEmpty
};

/*
Tweet fields contents
https://dev.twitter.com/docs/platform-objects/tweets
Expand Down
4 changes: 2 additions & 2 deletions STTwitter/STTwitterAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ - (void)postStatusUpdate:(NSString *)status
errorBlock:(void(^)(NSError *error))errorBlock {

if(status == nil) {
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:0 userInfo:@{NSLocalizedDescriptionKey : @"cannot post empty status"}];
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:STTwitterAPICannotPostEmptyStatus userInfo:@{NSLocalizedDescriptionKey : @"cannot post empty status"}];
errorBlock(error);
return;
}
Expand Down Expand Up @@ -871,7 +871,7 @@ - (void)postStatusUpdate:(NSString *)status
NSData *data = [NSData dataWithContentsOfURL:mediaURL];

if(data == nil) {
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:0 userInfo:@{NSLocalizedDescriptionKey : @"data is nil"}];
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:STTwitterAPIMediaDataIsEmpty userInfo:@{NSLocalizedDescriptionKey : @"data is nil"}];
errorBlock(error);
return;
}
Expand Down
5 changes: 5 additions & 0 deletions STTwitter/STTwitterAppOnly.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
# define STLog(...)
#endif

NS_ENUM(NSUInteger, STTwitterAppOnlyErrorCode) {
STTwitterAppOnlyCannotFindBearerTokenToBeInvalidated,
STTwitterAppOnlyCannotFindBearerTokenInResponse
};

@interface STTwitterAppOnly : NSObject <STTwitterProtocol> {

}
Expand Down
4 changes: 2 additions & 2 deletions STTwitter/STTwitterAppOnly.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ - (void)invalidateBearerTokenWithSuccessBlock:(void(^)())successBlock
errorBlock:(void(^)(NSError *error))errorBlock {

if(_bearerToken == nil) {
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:0 userInfo:@{NSLocalizedDescriptionKey : @"Cannot invalidate missing bearer token"}];
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:STTwitterAppOnlyCannotFindBearerTokenToBeInvalidated userInfo:@{NSLocalizedDescriptionKey : @"Cannot invalidate missing bearer token"}];
errorBlock(error);
return;
}
Expand Down Expand Up @@ -120,7 +120,7 @@ - (void)verifyCredentialsWithSuccessBlock:(void(^)(NSString *username))successBl

NSString *tokenType = [json valueForKey:@"token_type"];
if([tokenType isEqualToString:@"bearer"] == NO) {
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:0 userInfo:@{NSLocalizedDescriptionKey : @"Cannot find bearer token in server response"}];
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:STTwitterAppOnlyCannotFindBearerTokenInResponse userInfo:@{NSLocalizedDescriptionKey : @"Cannot find bearer token in server response"}];
errorBlock(error);
return;
}
Expand Down
4 changes: 4 additions & 0 deletions STTwitter/STTwitterHTML.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

#import <Foundation/Foundation.h>

NS_ENUM(NSUInteger, STTwitterHTMLErrorCode) {
STTwitterHTMLCannotPostWithoutCredentials
};

@interface STTwitterHTML : NSObject

- (void)getLoginForm:(void(^)(NSString *authenticityToken))successBlock
Expand Down
2 changes: 1 addition & 1 deletion STTwitter/STTwitterHTML.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ - (void)postLoginFormWithUsername:(NSString *)username

if([username length] == 0 || [password length] == 0) {
NSString *errorDescription = [NSString stringWithFormat:@"Missing credentials"];
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:0 userInfo:@{NSLocalizedDescriptionKey : errorDescription}];
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:STTwitterHTMLCannotPostWithoutCredentials userInfo:@{NSLocalizedDescriptionKey : errorDescription}];
errorBlock(error);
return;
}
Expand Down
4 changes: 4 additions & 0 deletions STTwitter/STTwitterOAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ extern NSString * const kSTPOSTDataKey;
...
*/

NS_ENUM(NSUInteger, STTwitterOAuthErrorCode) {
STTwitterOAuthCannotPostAccessTokenRequestWithoutPIN
};

@interface STTwitterOAuth : NSObject <STTwitterProtocol>

+ (instancetype)twitterOAuthWithConsumerName:(NSString *)consumerName
Expand Down
2 changes: 1 addition & 1 deletion STTwitter/STTwitterOAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ - (void)postAccessTokenRequestWithPIN:(NSString *)pin
errorBlock:(void(^)(NSError *error))errorBlock {

if([pin length] == 0) {
errorBlock([NSError errorWithDomain:NSStringFromClass([self class]) code:0 userInfo:@{NSLocalizedDescriptionKey : @"PIN needed"}]);
errorBlock([NSError errorWithDomain:NSStringFromClass([self class]) code:STTwitterOAuthCannotPostAccessTokenRequestWithoutPIN userInfo:@{NSLocalizedDescriptionKey : @"PIN needed"}]);
return;
}

Expand Down
7 changes: 7 additions & 0 deletions STTwitter/STTwitterOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
#import <Foundation/Foundation.h>
#import "STTwitterProtocol.h"

NS_ENUM(NSUInteger, STTwitterOSErrorCode) {
STTwitterOSSystemCannotAccessTwitter,
STTwitterOSCannotFindTwitterAccount,
STTwitterOSUserDeniedAccessToTheirAccounts,
STTwitterOSNoTwitterAccountIsAvailable
};

@class ACAccount;

@interface STTwitterOS : NSObject <STTwitterProtocol> {
Expand Down
8 changes: 4 additions & 4 deletions STTwitter/STTwitterOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ - (BOOL)hasAccessToTwitter {
- (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}];
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:STTwitterOSSystemCannotAccessTwitter userInfo:@{NSLocalizedDescriptionKey : message}];
errorBlock(error);
return;
}
Expand All @@ -91,7 +91,7 @@ - (void)verifyCredentialsWithSuccessBlock:(void(^)(NSString *username))successBl

if(accountType == nil) {
NSString *message = @"Cannot find Twitter account.";
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:0 userInfo:@{NSLocalizedDescriptionKey : message}];
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:STTwitterOSCannotFindTwitterAccount userInfo:@{NSLocalizedDescriptionKey : message}];
errorBlock(error);
return;
}
Expand All @@ -107,7 +107,7 @@ - (void)verifyCredentialsWithSuccessBlock:(void(^)(NSString *username))successBl
}

NSString *message = @"User denied access to their account(s).";
NSError *grantError = [NSError errorWithDomain:NSStringFromClass([self class]) code:0 userInfo:@{NSLocalizedDescriptionKey : message}];
NSError *grantError = [NSError errorWithDomain:NSStringFromClass([self class]) code:STTwitterOSUserDeniedAccessToTheirAccounts userInfo:@{NSLocalizedDescriptionKey : message}];
errorBlock(grantError);
return;
}
Expand All @@ -117,7 +117,7 @@ - (void)verifyCredentialsWithSuccessBlock:(void(^)(NSString *username))successBl

if([accounts count] == 0) {
NSString *message = @"No Twitter account available.";
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:0 userInfo:@{NSLocalizedDescriptionKey : message}];
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class]) code:STTwitterOSNoTwitterAccountIsAvailable userInfo:@{NSLocalizedDescriptionKey : message}];
errorBlock(error);
return;
}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
ReferencedContainer = "container:STTwitterDemoIOS.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-STHTTPRequestShowCurlDescription 1"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
ReferencedContainer = "container:STTwitterDemoOSX.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-STHTTPRequestShowDebugDescription 1"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand Down

0 comments on commit 41c9df9

Please sign in to comment.