Skip to content

Commit 5e6edf1

Browse files
authored
PCBC-901: attach error details to management exceptions (#71)
1 parent cf188e9 commit 5e6edf1

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/wrapper/common.cxx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
#include "wrapper.hxx"
1818

1919
#include "common.hxx"
20+
#include "core/utils/json.hxx"
2021

2122
#include <couchbase/error_codes.hxx>
2223

2324
#include <fmt/core.h>
25+
#include <tao/pegtl/parse_error.hpp>
2426

2527
#include <sstream>
2628
#include <zend_exceptions.h>
@@ -580,6 +582,15 @@ error_context_to_zval(const http_error_context& ctx, zval* return_value, std::st
580582
{
581583
add_assoc_stringl(return_value, "method", ctx.method.data(), ctx.method.size());
582584
add_assoc_stringl(return_value, "path", ctx.path.data(), ctx.path.size());
585+
try {
586+
if (auto json_body = core::utils::json::parse(ctx.http_body); json_body.is_object()) {
587+
if (const auto* errors = json_body.find("errors"); errors != nullptr) {
588+
enhanced_error_message = "errors=" + core::utils::json::generate(*errors);
589+
}
590+
}
591+
} catch (const tao::pegtl::parse_error&) {
592+
/* http body is not a JSON */
593+
}
583594
common_http_error_context_to_zval(ctx, return_value, enhanced_error_message);
584595
}
585596

src/wrapper/common.hxx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ couchbase_exception();
5555
COUCHBASE_API zend_class_entry*
5656
map_error_to_exception(const core_error_info& info);
5757

58-
COUCHBASE_API void
59-
error_context_to_zval(const core_error_info& info, zval* return_value);
60-
6158
COUCHBASE_API void
6259
create_exception(zval* return_value, const couchbase::php::core_error_info& error_info);
6360
} // namespace couchbase::php

0 commit comments

Comments
 (0)