Skip to content

Commit

Permalink
OAPIF: combine CURL error message and data payload (when it exists) t…
Browse files Browse the repository at this point in the history
…o form error message

Fixes #10653
  • Loading branch information
rouault committed Aug 27, 2024
1 parent 449d5f0 commit 7a5addb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
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 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

0 comments on commit 7a5addb

Please sign in to comment.