From ef59aa7535a3c8e17524d2dae5d5e49e158c05b7 Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Thu, 17 May 2012 20:11:05 +0300 Subject: [PATCH] On authentication error show a simpler alert. --- pithos-macos/PithosUtilities.h | 1 + pithos-macos/PithosUtilities.m | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/pithos-macos/PithosUtilities.h b/pithos-macos/PithosUtilities.h index 94e80d1..9a8b385 100644 --- a/pithos-macos/PithosUtilities.h +++ b/pithos-macos/PithosUtilities.h @@ -156,6 +156,7 @@ + (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; diff --git a/pithos-macos/PithosUtilities.m b/pithos-macos/PithosUtilities.m index 001689e..dcb0615 100644 --- a/pithos-macos/PithosUtilities.m +++ b/pithos-macos/PithosUtilities.m @@ -1188,6 +1188,10 @@ #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], @@ -1209,6 +1213,10 @@ } + (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, @@ -1230,6 +1238,18 @@ }); } ++ (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]; -- 1.7.10.4