@@ -536,16 +536,15 @@ [of_stdout writeFormat: @"☇ %@", [URL string]]; return true; } -- (bool)performRequest: (OFHTTPRequest *)request +- (void)client: (OFHTTPClient *)client + didEncounterException: (id)e + forRequest: (OFHTTPRequest *)request { - @try { - [_HTTPClient performRequest: request]; - return true; - } @catch (OFAddressTranslationFailedException *e) { + if ([e isKindOfClass: [OFAddressTranslationFailedException class]]) { if (!_quiet) [of_stdout writeString: @"\n"]; [of_stderr writeLine: OF_LOCALIZED(@"download_failed_address_translation", @@ -552,11 +551,11 @@ @"%[prog]: Failed to download <%[url]>!\n" @" Address translation failed: %[exception]", @"prog", [OFApplication programName], @"url", [[request URL] string], @"exception", e)]; - } @catch (OFConnectionFailedException *e) { + } else if ([e isKindOfClass: [OFConnectionFailedException class]]) { if (!_quiet) [of_stdout writeString: @"\n"]; [of_stderr writeLine: OF_LOCALIZED(@"download_failed_connection_failed", @@ -563,31 +562,31 @@ @"%[prog]: Failed to download <%[url]>!\n" @" Connection failed: %[exception]", @"prog", [OFApplication programName], @"url", [[request URL] string], @"exception", e)]; - } @catch (OFInvalidServerReplyException *e) { + } else if ([e isKindOfClass: [OFInvalidServerReplyException class]]) { if (!_quiet) [of_stdout writeString: @"\n"]; [of_stderr writeLine: OF_LOCALIZED(@"download_failed_invalid_server_reply", @"%[prog]: Failed to download <%[url]>!\n" @" Invalid server reply!", @"prog", [OFApplication programName], @"url", [[request URL] string])]; - } @catch (OFUnsupportedProtocolException *e) { + } else if ([e isKindOfClass: [OFUnsupportedProtocolException class]]) { if (!_quiet) [of_stdout writeString: @"\n"]; [of_stderr writeLine: OF_LOCALIZED(@"no_ssl_library", @"%[prog]: No TLS library loaded!\n" @" In order to download via https, you need to preload an " @"TLS library for ObjFW\n" @" such as ObjOpenSSL!", @"prog", [OFApplication programName])]; - } @catch (OFReadOrWriteFailedException *e) { + } else if ([e isKindOfClass: [OFReadOrWriteFailedException class]]) { OFString *error = OF_LOCALIZED( @"download_failed_read_or_write_failed_any", @"Read or write failed"); if (!_quiet) @@ -608,22 +607,24 @@ @" %[error]: %[exception]", @"prog", [OFApplication programName], @"url", [[request URL] string], @"error", error, @"exception", e)]; - } @catch (OFHTTPRequestFailedException *e) { + } else if ([e isKindOfClass: [OFHTTPRequestFailedException class]]) { if (!_quiet) [of_stdout writeFormat: @" ➜ %d\n", [[e response] statusCode]]; [of_stderr writeLine: OF_LOCALIZED(@"download_failed", @"%[prog]: Failed to download <%[url]>!", @"prog", [OFApplication programName], @"url", [[request URL] string])]; - } + } else + @throw e; - return false; + [self performSelector: @selector(downloadNextURL) + afterDelay: 0]; } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response @@ -905,15 +906,11 @@ request = [OFHTTPRequest requestWithURL: URL]; [request setHeaders: clientHeaders]; [request setMethod: OF_HTTP_REQUEST_METHOD_HEAD]; - if (![self performRequest: request]) { - _errorCode = 1; - goto next; - } - + [_HTTPClient performRequest: request]; return; } _detectedFileName = false; @@ -950,17 +947,13 @@ request = [OFHTTPRequest requestWithURL: URL]; [request setHeaders: clientHeaders]; [request setMethod: _method]; [request setBody: _body]; - if (![self performRequest: request]) { - _errorCode = 1; - goto next; - } - + [_HTTPClient performRequest: request]; return; next: [self performSelector: @selector(downloadNextURL) afterDelay: 0]; } @end