Skip to content

Commit

Permalink
Make errorToMap() a free function
Browse files Browse the repository at this point in the history
  • Loading branch information
manup committed Aug 1, 2021
1 parent 069dec0 commit c5bc4eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions de_web_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17067,19 +17067,19 @@ int DeRestPlugin::handleHttpRequest(const QHttpRequestHeader &hdr, QTcpSocket *s
{
if (resourceExist && req.hdr.httpMethod() == HttpGet)
{
rsp.list.append(d->errorToMap(ERR_RESOURCE_NOT_AVAILABLE, resource, "resource, " + resource + ", not available"));
rsp.list.append(errorToMap(ERR_RESOURCE_NOT_AVAILABLE, resource, "resource, " + resource + ", not available"));
}
else
{
rsp.list.append(d->errorToMap(ERR_METHOD_NOT_AVAILABLE, resource, "method, " + req.hdr.method() + ", not available for resource, " + resource));
rsp.list.append(errorToMap(ERR_METHOD_NOT_AVAILABLE, resource, "method, " + req.hdr.method() + ", not available for resource, " + resource));
}
rsp.httpStatus = HttpStatusNotFound;
ret = REQ_READY_SEND;
}
else
{
rsp.httpStatus = HttpStatusForbidden;
rsp.list.append(d->errorToMap(ERR_UNAUTHORIZED_USER, resource, "unauthorized user"));
rsp.list.append(errorToMap(ERR_UNAUTHORIZED_USER, resource, "unauthorized user"));
if (req.sock)
{
DBG_Printf(DBG_HTTP, "\thost: %s\n", qPrintable(req.sock->peerAddress().toString()));
Expand Down
6 changes: 3 additions & 3 deletions de_web_plugin_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ using namespace deCONZ::literals;
void getTime(quint32 *time, qint32 *tz, quint32 *dstStart, quint32 *dstEnd, qint32 *dstShift, quint32 *standardTime, quint32 *localTime, quint8 mode);
int getFreeSensorId(); // TODO needs to be part of a Database class

// REST API common
QVariantMap errorToMap(int id, const QString &ressource, const QString &description);

extern const quint64 macPrefixMask;

extern const quint64 celMacPrefix;
Expand Down Expand Up @@ -1222,9 +1225,6 @@ class DeRestPluginPrivate : public QObject
int handleCapabilitiesApi(const ApiRequest &req, ApiResponse &rsp);
int getCapabilities(const ApiRequest &req, ApiResponse &rsp);

// REST API common
QVariantMap errorToMap(int id, const QString &ressource, const QString &description);

// UPNP discovery
void initUpnpDiscovery();
void initDescriptionXml();
Expand Down
12 changes: 6 additions & 6 deletions rest_devices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ int RestDevices::putDeviceInstallCode(const ApiRequest &req, ApiResponse &rsp)

if (!ok || map.isEmpty())
{
rsp.list.append(plugin->errorToMap(ERR_INVALID_JSON, QString("/devices/%1/installcode").arg(uniqueid), QString("body contains invalid JSON")));
rsp.list.append(errorToMap(ERR_INVALID_JSON, QString("/devices/%1/installcode").arg(uniqueid), QString("body contains invalid JSON")));
rsp.httpStatus = HttpStatusBadRequest;
return REQ_READY_SEND;
}
Expand All @@ -502,14 +502,14 @@ int RestDevices::putDeviceInstallCode(const ApiRequest &req, ApiResponse &rsp)
cli.start("hashing-cli", QStringList() << "-i" << installCode);
if (!cli.waitForStarted(2000))
{
rsp.list.append(plugin->errorToMap(ERR_INTERNAL_ERROR, QString("/devices"), QString("internal error, %1, occured").arg(cli.error())));
rsp.list.append(errorToMap(ERR_INTERNAL_ERROR, QString("/devices"), QString("internal error, %1, occured").arg(cli.error())));
rsp.httpStatus = HttpStatusServiceUnavailable;
return REQ_READY_SEND;
}

if (!cli.waitForFinished(2000))
{
rsp.list.append(plugin->errorToMap(ERR_INTERNAL_ERROR, QString("/devices"), QString("internal error, %1, occured").arg(cli.error())));
rsp.list.append(errorToMap(ERR_INTERNAL_ERROR, QString("/devices"), QString("internal error, %1, occured").arg(cli.error())));
rsp.httpStatus = HttpStatusServiceUnavailable;
return REQ_READY_SEND;
}
Expand All @@ -532,7 +532,7 @@ int RestDevices::putDeviceInstallCode(const ApiRequest &req, ApiResponse &rsp)

if (mmoHash.isEmpty())
{
rsp.list.append(plugin->errorToMap(ERR_INTERNAL_ERROR, QLatin1String("/devices"), QLatin1String("internal error, failed to calc mmo hash, occured")));
rsp.list.append(errorToMap(ERR_INTERNAL_ERROR, QLatin1String("/devices"), QLatin1String("internal error, failed to calc mmo hash, occured")));
rsp.httpStatus = HttpStatusServiceUnavailable;
return REQ_READY_SEND;
}
Expand All @@ -557,13 +557,13 @@ int RestDevices::putDeviceInstallCode(const ApiRequest &req, ApiResponse &rsp)
}
else
{
rsp.list.append(plugin->errorToMap(ERR_INVALID_VALUE, QString("/devices"), QString("invalid value, %1, for parameter, installcode").arg(installCode)));
rsp.list.append(errorToMap(ERR_INVALID_VALUE, QString("/devices"), QString("invalid value, %1, for parameter, installcode").arg(installCode)));
rsp.httpStatus = HttpStatusBadRequest;
}
}
else
{
rsp.list.append(plugin->errorToMap(ERR_MISSING_PARAMETER, QString("/devices/%1/installcode").arg(uniqueid), QString("missing parameters in body")));
rsp.list.append(errorToMap(ERR_MISSING_PARAMETER, QString("/devices/%1/installcode").arg(uniqueid), QString("missing parameters in body")));
rsp.httpStatus = HttpStatusBadRequest;
}

Expand Down

0 comments on commit c5bc4eb

Please sign in to comment.