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

OAPIF/OGCAPI: combine CURL error message and data payload (when it exists) to form error message #10658

Merged
merged 2 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 9 additions & 1 deletion autotest/ogr/ogr_oapif.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ def test_ogr_oapif_errors():
handler = webserver.SequentialHandler()
handler.add("GET", "/oapif/collections", 404)
with webserver.install_http_handler(handler):
with pytest.raises(Exception):
with pytest.raises(Exception, match="HTTP error code : 404"):
ogr.Open("OAPIF:http://localhost:%d/oapif" % gdaltest.webserver_port)

handler = webserver.SequentialHandler()
handler.add("GET", "/oapif/collections", 404, {}, "unavailable resource")
with webserver.install_http_handler(handler):
with pytest.raises(
Exception, match="HTTP error code : 404, unavailable resource"
):
ogr.Open("OAPIF:http://localhost:%d/oapif" % gdaltest.webserver_port)

# No Content-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
13 changes: 9 additions & 4 deletions ogr/ogrsf_frmts/wfs/ogroapifdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,15 @@ bool OGROAPIFDataset::Download(const CPLString &osURL, const char *pszAccept,

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
Loading