QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgsserverexception.h
Go to the documentation of this file.
1/***************************************************************************
2 qgserverexception.h
3 ------------------------
4 begin : January 11, 2017
5 copyright : (C) 2017 by David Marteau
6 email : david dot marteau at 3liz dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSSERVEREXCEPTION_H
19#define QGSSERVEREXCEPTION_H
20
21
22#include <nlohmann/json.hpp>
23
24#include "qgis_server.h"
25#include "qgis_sip.h"
26#include "qgsexception.h"
27
28#include <QByteArray>
29#include <QString>
30
31#ifndef SIP_RUN
32using namespace nlohmann;
33#endif
34
35
41#ifndef SIP_RUN
42class SERVER_EXPORT QgsServerException : public QgsException
43{
44#else
45class SERVER_EXPORT QgsServerException
46{
47#endif
48 public:
50 QgsServerException( const QString &message, int responseCode = 500 );
51
55 int responseCode() const { return mResponseCode; }
56
65 virtual QByteArray formatResponse( QString &responseFormat SIP_OUT ) const;
66
67 private:
68 int mResponseCode;
69};
70
80#ifndef SIP_RUN
81class SERVER_EXPORT QgsOgcServiceException : public QgsServerException
82{
83#else
84class SERVER_EXPORT QgsOgcServiceException
85{
86#endif
87 public:
89 QgsOgcServiceException( const QString &code, const QString &message, const QString &locator = QString(), int responseCode = 200, const QString &version = QStringLiteral( "1.3.0" ) );
90
92 QString message() const { return mMessage; }
93
95 QString code() const { return mCode; }
96
98 QString locator() const { return mLocator; }
99
101 QString version() const { return mVersion; }
102
103 QByteArray formatResponse( QString &responseFormat SIP_OUT ) const override;
104
105 private:
106 QString mCode;
107 QString mMessage;
108 QString mLocator;
109 QString mVersion;
110};
111
118#ifndef SIP_RUN
120{
121 public:
122
129 QgsBadRequestException( const QString &code, const QString &message, const QString &locator = QString() )
131 {}
132};
133#endif
134
135#ifndef SIP_RUN // No API exceptions for SIP, see python/server/qgsserverexception.sip
136
147class SERVER_EXPORT QgsServerApiException : public QgsServerException
148{
149 public:
151 QgsServerApiException( const QString &code, const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 200 )
152 : QgsServerException( message, responseCode )
153 , mCode( code )
154 , mMimeType( mimeType )
155 {
156 }
157
158 QByteArray formatResponse( QString &responseFormat SIP_OUT ) const override
159 {
160 responseFormat = mMimeType;
161 const json data {
162 {
163 { "code", mCode.toStdString() },
164 { "description", what().toStdString() },
165 }
166 };
167
168 return QByteArray::fromStdString( data.dump() );
169 }
170
171 private:
172 QString mCode;
173 QString mMimeType;
174};
175
176
188{
189 public:
191 QgsServerApiInternalServerError( const QString &message = QStringLiteral( "Internal server error" ), const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 500 )
192 : QgsServerApiException( QStringLiteral( "Internal server error" ), message, mimeType, responseCode )
193 {
194 }
195};
196
197
209{
210 public:
212 QgsServerApiNotFoundError( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 404 )
213 : QgsServerApiException( QStringLiteral( "API not found error" ), message, mimeType, responseCode )
214 {
215 }
216};
217
218
230{
231 public:
233 QgsServerApiBadRequestException( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 400 )
234 : QgsServerApiException( QStringLiteral( "Bad request error" ), message, mimeType, responseCode )
235 {
236 }
237};
238
239
251{
252 public:
254 QgsServerApiPermissionDeniedException( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 403 )
255 : QgsServerApiException( QStringLiteral( "Forbidden" ), message, mimeType, responseCode )
256 {
257 }
258};
259
271{
272 public:
274 QgsServerApiImproperlyConfiguredException( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 500 )
275 : QgsServerApiException( QStringLiteral( "Improperly configured error" ), message, mimeType, responseCode )
276 {
277 }
278};
279
280
292{
293 public:
295 QgsServerApiNotImplementedException( const QString &message = QStringLiteral( "Requested method is not implemented" ), const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 500 )
296 : QgsServerApiException( QStringLiteral( "Not implemented error" ), message, mimeType, responseCode )
297 {
298 }
299};
300
301
312{
313 public:
315 QgsServerApiInvalidMimeTypeException( const QString &message = QStringLiteral( "The Accept header submitted in the request did not support any of the media types supported by the server for the requested resource" ), const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 406 )
316 : QgsServerApiException( QStringLiteral( "Invalid mime-type" ), message, mimeType, responseCode )
317 {
318 }
319};
320#endif // no API exceptions for SIP
321
322#endif
QgsBadRequestException(const QString &code, const QString &message, const QString &locator=QString())
Constructor for QgsBadRequestException (HTTP error code 400).
QString what() const
QgsException(const QString &message)
Constructor for QgsException, with the specified error message.
QString locator() const
Returns the locator.
QgsOgcServiceException(const QString &code, const QString &message, const QString &locator=QString(), int responseCode=200, const QString &version=QStringLiteral("1.3.0"))
Construction.
QString message() const
Returns the exception message.
QString code() const
Returns the exception code.
QString version() const
Returns the exception version.
QgsServerApiBadRequestException(const QString &message, const QString &mimeType=QStringLiteral("application/json"), int responseCode=400)
Construction.
QgsServerApiException(const QString &code, const QString &message, const QString &mimeType=QStringLiteral("application/json"), int responseCode=200)
Construction.
QByteArray formatResponse(QString &responseFormat) const override
Formats the exception for sending to client.
QgsServerApiImproperlyConfiguredException(const QString &message, const QString &mimeType=QStringLiteral("application/json"), int responseCode=500)
Construction.
QgsServerApiInternalServerError(const QString &message=QStringLiteral("Internal server error"), const QString &mimeType=QStringLiteral("application/json"), int responseCode=500)
Construction.
QgsServerApiInvalidMimeTypeException(const QString &message=QStringLiteral("The Accept header submitted in the request did not support any of the media types supported by the server for the requested resource"), const QString &mimeType=QStringLiteral("application/json"), int responseCode=406)
Construction.
QgsServerApiNotFoundError(const QString &message, const QString &mimeType=QStringLiteral("application/json"), int responseCode=404)
Construction.
QgsServerApiNotImplementedException(const QString &message=QStringLiteral("Requested method is not implemented"), const QString &mimeType=QStringLiteral("application/json"), int responseCode=500)
Construction.
QgsServerApiPermissionDeniedException(const QString &message, const QString &mimeType=QStringLiteral("application/json"), int responseCode=403)
Construction.
int responseCode() const
Returns the return HTTP response code associated with this exception.
QgsServerException(const QString &message, int responseCode=500)
Constructor.
#define SIP_OUT
Definition qgis_sip.h:58