On authentication error show a simpler alert.
authorMiltiadis Vasilakis <mvasilak@gmail.com>
Thu, 17 May 2012 17:11:05 +0000 (20:11 +0300)
committerMiltiadis Vasilakis <mvasilak@gmail.com>
Thu, 17 May 2012 17:11:05 +0000 (20:11 +0300)
pithos-macos/PithosUtilities.h
pithos-macos/PithosUtilities.m

index 94e80d1..9a8b385 100644 (file)
 
 + (void)httpRequestErrorAlertWithRequest:(ASIPithosRequest *)request;
 + (void)unexpectedResponseStatusAlertWithRequest:(ASIPithosRequest *)request;
++ (void)httpAuthenticationError;
 + (void)fileActionFailedAlertWithTitle:(NSString *)title message:(NSString *)message error:(NSError *)error;
 
 + (ASIPithosRequest *)prepareRequest:(ASIPithosRequest *)request priority:(NSOperationQueuePriority)priority;
index 001689e..dcb0615 100644 (file)
 #pragma mark Alerts
 
 + (void)httpRequestErrorAlertWithRequest:(ASIPithosRequest *)request {
+    if (request.responseStatusCode == 401) {
+        [self httpAuthenticationError];
+        return;
+    }
     NSString *message = [NSString stringWithFormat:
                          @"HTTP request error: %@\n%@ URL: %@\nRequest Headers: %@\nResponse Headers: %@\nResponse String: %@", 
                          [[request error] localizedDescription], 
 }
 
 + (void)unexpectedResponseStatusAlertWithRequest:(ASIPithosRequest *)request {
+    if (request.responseStatusCode == 401) {
+        [self httpAuthenticationError];
+        return;
+    }
     NSString *message = [NSString stringWithFormat:
                          @"Unexpected response status %d: %@\n%@ URL: %@\nRequest Headers: %@\nResponse Headers: %@\nResponse String: %@", 
                          request.responseStatusCode, 
     });
 }
 
++ (void)httpAuthenticationError {
+    dispatch_async(dispatch_get_main_queue(), ^{
+        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+        NSAlert *alert = [[[NSAlert alloc] init] autorelease];
+        [alert setMessageText:@"Authentication Error"];
+        [alert setInformativeText:@"Authentication error, please check your token or login again"];
+        [alert addButtonWithTitle:@"OK"];
+        [alert runModal];
+        [pool drain];
+    });
+}
+
 + (void)fileActionFailedAlertWithTitle:(NSString *)title message:(NSString *)message error:(NSError *)error {
     dispatch_async(dispatch_get_main_queue(), ^{
         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];