mirror of https://github.com/vitalif/grive2
Retry upload on XML error instead of crashing
Sometimes the Google Drive API sends malformed XML which crashes grive. This patch adds a simple try-catch to Resource::Upload that retries the upload if an XML exception is thrown from AuthAgent::Put.pull/40/head
parent
84785ec473
commit
3775572f46
|
@ -607,11 +607,23 @@ bool Resource::Upload(
|
||||||
os::Sleep( 5 );
|
os::Sleep( 5 );
|
||||||
}
|
}
|
||||||
|
|
||||||
http::StringResponse str ;
|
try {
|
||||||
if ( post )
|
http::StringResponse str ;
|
||||||
http->Post( link, meta, &str, hdr ) ;
|
if ( post )
|
||||||
else
|
http->Post( link, meta, &str, hdr ) ;
|
||||||
http->Put( link, meta, &str, hdr ) ;
|
else
|
||||||
|
http->Put( link, meta, &str, hdr ) ;
|
||||||
|
} catch ( Error &e ) {
|
||||||
|
std::string const *info = boost::get_error_info<xml::TreeBuilder::ExpatApiError>(e);
|
||||||
|
if ( info && (*info == "XML_Parse") ) {
|
||||||
|
Log( "Error parsing pre-upload response XML, retrying whole upload in 5s",
|
||||||
|
log::warning );
|
||||||
|
retrying = true;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
http::Header uphdr ;
|
http::Header uphdr ;
|
||||||
uphdr.Add( "Expect:" ) ;
|
uphdr.Add( "Expect:" ) ;
|
||||||
|
@ -622,7 +634,19 @@ bool Resource::Upload(
|
||||||
http::XmlResponse xml ;
|
http::XmlResponse xml ;
|
||||||
|
|
||||||
long http_code = 0;
|
long http_code = 0;
|
||||||
http_code = http->Put( uplink, &file, &xml, uphdr ) ;
|
try {
|
||||||
|
http_code = http->Put( uplink, &file, &xml, uphdr ) ;
|
||||||
|
} catch ( Error &e ) {
|
||||||
|
std::string const *info = boost::get_error_info<xml::TreeBuilder::ExpatApiError>(e);
|
||||||
|
if ( info && (*info == "XML_Parse") ) {
|
||||||
|
Log( "Error parsing response XML, retrying whole upload in 5s",
|
||||||
|
log::warning );
|
||||||
|
retrying = true;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( http_code == 410 || http_code == 412 ) {
|
if ( http_code == 410 || http_code == 412 ) {
|
||||||
Log( "request failed with %1%, retrying whole upload in 5s", http_code,
|
Log( "request failed with %1%, retrying whole upload in 5s", http_code,
|
||||||
|
|
Loading…
Reference in New Issue