Skip to content

Commit

Permalink
Support sending custom status codes via WebAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
Piccirello committed Jul 15, 2024
1 parent 3acd540 commit 3da5c73
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/webui/api/apicontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void APIResult::clear()
data.clear();
mimeType.clear();
filename.clear();
statusCode = 0;
}

APIController::APIController(IApplication *app, QObject *parent)
Expand Down Expand Up @@ -105,3 +106,8 @@ void APIController::setResult(const QByteArray &result, const QString &mimeType,
m_result.mimeType = mimeType;
m_result.filename = filename;
}

void APIController::setStatus(const int statusCode)
{
m_result.statusCode = statusCode;
}
3 changes: 3 additions & 0 deletions src/webui/api/apicontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct APIResult
QVariant data;
QString mimeType;
QString filename;
int statusCode;

void clear();
};
Expand All @@ -67,6 +68,8 @@ class APIController : public ApplicationComponent<QObject>
void setResult(const QJsonObject &result);
void setResult(const QByteArray &result, const QString &mimeType = {}, const QString &filename = {});

void setStatus(int statusCode);

private:
StringMap m_params;
DataMap m_data;
Expand Down
3 changes: 3 additions & 0 deletions src/webui/webapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ void WebApplication::doProcessRequest()
try
{
const APIResult result = controller->run(action, m_params, data);
if (result.statusCode != 0)
status(result.statusCode);

switch (result.data.userType())
{
case QMetaType::QJsonDocument:
Expand Down

0 comments on commit 3da5c73

Please sign in to comment.