Skip to content

PCBC-901: attach error details to management exceptions #71

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

Merged
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
11 changes: 11 additions & 0 deletions src/wrapper/common.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
#include "wrapper.hxx"

#include "common.hxx"
#include "core/utils/json.hxx"

#include <couchbase/error_codes.hxx>

#include <fmt/core.h>
#include <tao/pegtl/parse_error.hpp>

#include <sstream>
#include <zend_exceptions.h>
Expand Down Expand Up @@ -580,6 +582,15 @@ error_context_to_zval(const http_error_context& ctx, zval* return_value, std::st
{
add_assoc_stringl(return_value, "method", ctx.method.data(), ctx.method.size());
add_assoc_stringl(return_value, "path", ctx.path.data(), ctx.path.size());
try {
if (auto json_body = core::utils::json::parse(ctx.http_body); json_body.is_object()) {
if (const auto* errors = json_body.find("errors"); errors != nullptr) {
enhanced_error_message = "errors=" + core::utils::json::generate(*errors);
}
}
} catch (const tao::pegtl::parse_error&) {
/* http body is not a JSON */
}
common_http_error_context_to_zval(ctx, return_value, enhanced_error_message);
}

Expand Down
3 changes: 0 additions & 3 deletions src/wrapper/common.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ couchbase_exception();
COUCHBASE_API zend_class_entry*
map_error_to_exception(const core_error_info& info);

COUCHBASE_API void
error_context_to_zval(const core_error_info& info, zval* return_value);

COUCHBASE_API void
create_exception(zval* return_value, const couchbase::php::core_error_info& error_info);
} // namespace couchbase::php