Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F115925
D93.1732839215.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D93.1732839215.diff
View Options
diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt
--- a/src/client/CMakeLists.txt
+++ b/src/client/CMakeLists.txt
@@ -3,6 +3,7 @@
client-model.cpp
client.cpp
clientutil.cpp
+ status-utils.cpp
actions/auth.cpp
actions/sync.cpp
actions/paginate.cpp
diff --git a/src/client/status-utils.hpp b/src/client/status-utils.hpp
--- a/src/client/status-utils.hpp
+++ b/src/client/status-utils.hpp
@@ -1,12 +1,13 @@
/*
* This file is part of libkazv.
- * SPDX-FileCopyrightText: 2020 Tusooa Zhu <tusooa@kazv.moe>
+ * SPDX-FileCopyrightText: 2020-2024 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
-
+#include <libkazv-config.hpp>
#include <context.hpp>
+#include <basejob.hpp>
namespace Kazv
{
@@ -19,6 +20,17 @@
return EffectStatus(/* succ = */ false);
};
};
+
+ struct ReturnEffectStatusT
+ {
+ EffectStatus st;
+
+ template<class Context>
+ EffectStatus operator()(Context &&) const
+ {
+ return st;
+ };
+ };
}
/**
@@ -29,32 +41,11 @@
/**
* A effect that returns a failed EffectStatus upon invocation.
*/
- template<class Resp>
- constexpr auto failWithResponse(Resp &&r)
- {
- auto code = r.errorCode();
- auto msg = std::forward<Resp>(r).errorMessage();
- auto d = json{
- {"error", msg},
- {"errorCode", code},
- };
- return [data=JsonWrap(d)](auto &&) {
- return EffectStatus(/* succ = */ false, data);
- };
- }
+ detail::ReturnEffectStatusT failWithResponse(const BaseJob::Response &r);
/**
* An effect that returns a failed EffectStatus with the given
* error code and message.
*/
- inline auto failEffect(std::string errorCode, std::string errorMsg)
- {
- auto d = json{
- {"error", errorMsg},
- {"errorCode", errorCode},
- };
- return [data=JsonWrap(d)](auto &&) {
- return EffectStatus(/* succ = */ false, data);
- };
- }
+ detail::ReturnEffectStatusT failEffect(std::string errorCode, std::string errorMsg);
}
diff --git a/src/client/status-utils.cpp b/src/client/status-utils.cpp
new file mode 100644
--- /dev/null
+++ b/src/client/status-utils.cpp
@@ -0,0 +1,36 @@
+/*
+ * This file is part of libkazv.
+ * SPDX-FileCopyrightText: 2020-2024 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <libkazv-config.hpp>
+#include "status-utils.hpp"
+
+namespace Kazv
+{
+ detail::ReturnEffectStatusT failWithResponse(const BaseJob::Response &r)
+ {
+ auto code = r.errorCode();
+ auto msg = r.errorMessage();
+ auto d = json{
+ {"error", msg},
+ {"errorCode", code},
+ };
+ return detail::ReturnEffectStatusT{
+ EffectStatus(/* succ = */ false, JsonWrap(d))
+ };
+ }
+
+ detail::ReturnEffectStatusT failEffect(std::string errorCode, std::string errorMsg)
+ {
+ auto d = json{
+ {"error", errorMsg},
+ {"errorCode", errorCode},
+ };
+
+ return detail::ReturnEffectStatusT{
+ EffectStatus(/* succ = */ false, JsonWrap(d))
+ };
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 4:13 PM (21 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41255
Default Alt Text
D93.1732839215.diff (3 KB)
Attached To
Mode
D93: Make failWithResponse() non-constexpr
Attached
Detach File
Event Timeline
Log In to Comment