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

Failed Uploads Fix #4

Open
AcriCAA opened this issue Jan 15, 2015 · 1 comment
Open

Failed Uploads Fix #4

AcriCAA opened this issue Jan 15, 2015 · 1 comment

Comments

@AcriCAA
Copy link
Contributor

AcriCAA commented Jan 15, 2015

Lloyd and I think we figured out the reason why uploads are failing. In TripManager.m there is a switch statement which runs through a bunch of server responses and if it does not receive any of them defaults to a kServerError message which prints "Upload Failed. Try again later." We just need to rewrite the switch statement to cover all scenarios of server responses because uploads are going through but the server is not passing a message back that the switch statement can interpret so it is defaulting to a failed upload.

\- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    // this method is called when the server has determined that it
    // has enough information to create the NSURLResponse
    NSLog(@"didReceiveResponse: %@", response);

```
NSHTTPURLResponse *httpResponse = nil;
if ( [response isKindOfClass:[NSHTTPURLResponse class]] &&
    ( httpResponse = (NSHTTPURLResponse*)response ) )
{
    BOOL success = NO;
    NSString *title   = nil;
    NSString *message = nil;
    switch ( [httpResponse statusCode] )
    {
        case 200:
        case 201:
            success = YES;
            title   = kSuccessTitle;
            message = kSaveSuccess;
            break;
        case 202:
            success = YES;
            title   = kSuccessTitle;
            message = kSaveAccepted;
            break;
        case 500:
        default:
            title = @"Internal Server Error";
            //message = [NSString stringWithFormat:@"%d", [httpResponse statusCode]];
            message = kServerError;
    }

    NSLog(@"%@: %@", title, message);

    //
    // DEBUG
    NSLog(@"+++++++DEBUG didReceiveResponse %@: %@", [response URL],[(NSHTTPURLResponse*)response allHeaderFields]);

    if ( success )
    {
        [note setUploaded:[NSDate date]];

        NSError *error;
        if (![managedObjectContext save:&error]) {
            // Handle the error.
            NSLog(@"TripManager setUploaded error %@, %@", error, [error localizedDescription]);
        }

        [uploadingView loadingComplete:kSuccessTitle delayInterval:.7];
    } else {

        [uploadingView loadingComplete:kServerError delayInterval:1.5];
    }
}

// it can be called multiple times, for example in the case of a
// redirect, so each time we reset the data.

// receivedData is declared as a method instance elsewhere
[receivedDataNoted setLength:0];
```

}
@flibbertigibbet
Copy link
Contributor

What other success server responses might get sent? Perhaps it would be better to check for a general 2XX OK response. (Surely there's an iOS-y way to do that cleanly.)

Given that upload issues also appear on Android, I suspect there's something going on server-side that's at least part of the issue.

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

2 participants