Skip to content

Commit

Permalink
OGCAPI: combine CURL error message and data payload (when it exists) …
Browse files Browse the repository at this point in the history
…to form error message
  • Loading branch information
rouault committed Aug 27, 2024
1 parent 7a5addb commit 1971eac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion autotest/gdrivers/ogcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,10 @@ def test_ogr_ogcapi_raster(api, collection, tmp_path):
)
def test_ogc_api_wrong_collection(api, of_type):

with pytest.raises(Exception, match="Invalid data collection"):
with pytest.raises(
Exception,
match=r"HTTP error code : 400, <h1>GNOSIS Map Server \(OGCAPI\) - 400 Bad Request</h1><h3>Invalid data collection</h3>",
):
gdal.OpenEx(
f"OGCAPI:http://127.0.0.1:{gdaltest.webserver_port}/fakeogcapi/collections/NOT_EXISTS",
of_type,
Expand Down
13 changes: 9 additions & 4 deletions frmts/ogcapi/gdalogcapidataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,15 @@ bool OGCAPIDataset::Download(const CPLString &osURL, const char *pszPostContent,

if (psResult->pszErrBuf != nullptr)
{
CPLError(CE_Failure, CPLE_AppDefined, "%s",
psResult->pabyData
? reinterpret_cast<const char *>(psResult->pabyData)
: psResult->pszErrBuf);
std::string osErrorMsg(psResult->pszErrBuf);
const char *pszData =
reinterpret_cast<const char *>(psResult->pabyData);
if (pszData)
{
osErrorMsg += ", ";
osErrorMsg.append(pszData, CPLStrnlen(pszData, 1000));
}
CPLError(CE_Failure, CPLE_AppDefined, "%s", osErrorMsg.c_str());
CPLHTTPDestroyResult(psResult);
return false;
}
Expand Down

0 comments on commit 1971eac

Please sign in to comment.