Skip to content

Commit 9f55656

Browse files
Fix message extraction logic and add missing model.hpp file to getFiles for C++ SDK
1 parent 3fd5218 commit 9f55656

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

examples/cpp/include/appwrite/exception.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ class Exception : public std::exception {
1111
Exception(const std::string& message, int code = 0, const std::string& response = "", const std::string& type = "")
1212
: message_(message), code_(code), response_(response), type_(type) {
1313

14-
if (type_.empty() || message_ == response_) {
14+
if (type_.empty() || message_.empty()) {
1515
try {
1616
if (!response_.empty() && response_.front() == '{') {
1717
auto json = nlohmann::json::parse(response_);
18-
if (json.contains("message") && json["message"].is_string() && message_ == response_) {
18+
if (json.contains("message") && json["message"].is_string() && message_.empty()) {
1919
message_ = json["message"].get<std::string>();
2020
}
2121
if (json.contains("type") && json["type"].is_string() && type_.empty()) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include <optional>
4+
#include <nlohmann/json.hpp>
5+
6+
namespace appwrite {
7+
8+
class Model {
9+
public:
10+
virtual ~Model() = default;
11+
virtual nlohmann::json toJson() const = 0;
12+
};
13+
14+
} // namespace appwrite

src/SDK/Language/Cpp.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ public function getFiles(): array
159159
'destination' => 'include/appwrite/services/{{ service.name | caseSnake }}.hpp',
160160
'template' => 'cpp/include/services/service.hpp.twig',
161161
],
162+
[
163+
'scope' => 'default',
164+
'destination' => 'include/appwrite/model.hpp',
165+
'template' => 'cpp/include/model.hpp.twig',
166+
],
162167
[
163168
'scope' => 'definition',
164169
'destination' => 'include/appwrite/models/{{ definition.name | caseSnake }}.hpp',

templates/cpp/include/exception.hpp.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ public:
1111
Exception(const std::string& message, int code = 0, const std::string& response = "", const std::string& type = "")
1212
: message_(message), code_(code), response_(response), type_(type) {
1313

14-
if (type_.empty() || message_ == response_) {
14+
if (type_.empty() || message_.empty()) {
1515
try {
1616
if (!response_.empty() && response_.front() == '{') {
1717
auto json = nlohmann::json::parse(response_);
18-
if (json.contains("message") && json["message"].is_string() && message_ == response_) {
18+
if (json.contains("message") && json["message"].is_string() && message_.empty()) {
1919
message_ = json["message"].get<std::string>();
2020
}
2121
if (json.contains("type") && json["type"].is_string() && type_.empty()) {

0 commit comments

Comments
 (0)