From Jason Beverage, "Here is a small change to the CURL plugin to distinguish between a 400 level error and a 500 level error.

If a 400 level error occurs, a FILE_NOT_FOUND ReadResult is appropriate.

If a 500 level error occurs (such a 503, Service unavailable), the application might want to try to load the file again in a few seconds/minutes.  This submission returns ERROR_IN_READING_FILE if a 500 level error occurs so that clients can easily distinguish between the errors.

The actual error code is also added to the "message" of the ReadResult so if a client needs more information, they can just parse the message to retrieve the error code."
This commit is contained in:
Robert Osfield
2008-10-14 16:57:37 +00:00
parent 36a93d9cf3
commit 1bbab1fcc7

View File

@@ -163,10 +163,32 @@ osgDB::ReaderWriter::ReadResult EasyCurl::read(const std::string& proxyAddress,
curl_easy_getinfo(_curl, CURLINFO_RESPONSE_CODE, &code);
}
if (code>=400)
//If the code is greater than 400, there was an error
if (code >= 400)
{
osg::notify(osg::NOTICE)<<"Error: libcurl read error, file="<<fileName<<", error code = "<<code<<std::endl;
return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND;
osgDB::ReaderWriter::ReadResult::ReadStatus status;
//Distinguish between a client error and a server error
if (code < 500)
{
//A 400 level error indicates a client error
status = osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND;
}
else
{
//A 500 level error indicates a server error
status = osgDB::ReaderWriter::ReadResult::ERROR_IN_READING_FILE;
}
osgDB::ReaderWriter::ReadResult rr(status);
//Add the error code to the ReadResult
std::stringstream message;
message << "error code = " << code;
rr.message() = message.str();
return rr;
}
return osgDB::ReaderWriter::ReadResult::FILE_LOADED;