QGIS API Documentation 3.99.0-Master (d270888f95f)
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 Qt::StringLiterals;
33using namespace nlohmann;
34#endif
35
36
42#ifndef SIP_RUN
43class SERVER_EXPORT QgsServerException : public QgsException
44{
45#else
46class SERVER_EXPORT QgsServerException
47{
48#endif
49 public:
51 QgsServerException( const QString &message, int responseCode = 500 );
52
56 int responseCode() const { return mResponseCode; }
57
66 virtual QByteArray formatResponse( QString &responseFormat SIP_OUT ) const;
67
68 private:
69 int mResponseCode;
70};
71
81#ifndef SIP_RUN
82class SERVER_EXPORT QgsOgcServiceException : public QgsServerException
83{
84#else
85class SERVER_EXPORT QgsOgcServiceException
86{
87#endif
88 public:
90 QgsOgcServiceException( const QString &code, const QString &message, const QString &locator = QString(), int responseCode = 200, const QString &version = u"1.3.0"_s );
91
93 QString message() const { return mMessage; }
94
96 QString code() const { return mCode; }
97
99 QString locator() const { return mLocator; }
100
102 QString version() const { return mVersion; }
103
104 QByteArray formatResponse( QString &responseFormat SIP_OUT ) const override;
105
106 private:
107 QString mCode;
108 QString mMessage;
109 QString mLocator;
110 QString mVersion;
111};
112
119#ifndef SIP_RUN
121{
122 public:
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 = u"application/json"_s, 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 = u"Internal server error"_s, const QString &mimeType = u"application/json"_s, int responseCode = 500 )
192 : QgsServerApiException( u"Internal server error"_s, message, mimeType, responseCode )
193 {
194 }
195};
196
197
209{
210 public:
212 QgsServerApiNotFoundError( const QString &message, const QString &mimeType = u"application/json"_s, int responseCode = 404 )
213 : QgsServerApiException( u"API not found error"_s, message, mimeType, responseCode )
214 {
215 }
216};
217
218
230{
231 public:
233 QgsServerApiBadRequestException( const QString &message, const QString &mimeType = u"application/json"_s, int responseCode = 400 )
234 : QgsServerApiException( u"Bad request error"_s, message, mimeType, responseCode )
235 {
236 }
237};
238
239
251{
252 public:
254 QgsServerApiPermissionDeniedException( const QString &message, const QString &mimeType = u"application/json"_s, int responseCode = 403 )
255 : QgsServerApiException( u"Forbidden"_s, message, mimeType, responseCode )
256 {
257 }
258};
259
271{
272 public:
274 QgsServerApiImproperlyConfiguredException( const QString &message, const QString &mimeType = u"application/json"_s, int responseCode = 500 )
275 : QgsServerApiException( u"Improperly configured error"_s, message, mimeType, responseCode )
276 {
277 }
278};
279
280
292{
293 public:
295 QgsServerApiNotImplementedException( const QString &message = u"Requested method is not implemented"_s, const QString &mimeType = u"application/json"_s, int responseCode = 500 )
296 : QgsServerApiException( u"Not implemented error"_s, message, mimeType, responseCode )
297 {
298 }
299};
300
301
312{
313 public:
315 QgsServerApiInvalidMimeTypeException( const QString &message = u"The Accept header submitted in the request did not support any of the media types supported by the server for the requested resource"_s, const QString &mimeType = u"application/json"_s, int responseCode = 406 )
316 : QgsServerApiException( u"Invalid mime-type"_s, 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.
QString message() const
Returns the exception message.
QString code() const
Returns the exception code.
QString version() const
Returns the exception version.
QgsOgcServiceException(const QString &code, const QString &message, const QString &locator=QString(), int responseCode=200, const QString &version=u"1.3.0"_s)
Construction.
QgsServerApiBadRequestException(const QString &message, const QString &mimeType=u"application/json"_s, int responseCode=400)
Construction.
QgsServerApiException(const QString &code, const QString &message, const QString &mimeType=u"application/json"_s, int responseCode=200)
Construction.
QByteArray formatResponse(QString &responseFormat) const override
Formats the exception for sending to client.
QgsServerApiImproperlyConfiguredException(const QString &message, const QString &mimeType=u"application/json"_s, int responseCode=500)
Construction.
QgsServerApiInternalServerError(const QString &message=u"Internal server error"_s, const QString &mimeType=u"application/json"_s, int responseCode=500)
Construction.
QgsServerApiInvalidMimeTypeException(const QString &message=u"The Accept header submitted in the request did not support any of the media types supported by the server for the requested resource"_s, const QString &mimeType=u"application/json"_s, int responseCode=406)
Construction.
QgsServerApiNotFoundError(const QString &message, const QString &mimeType=u"application/json"_s, int responseCode=404)
Construction.
QgsServerApiNotImplementedException(const QString &message=u"Requested method is not implemented"_s, const QString &mimeType=u"application/json"_s, int responseCode=500)
Construction.
QgsServerApiPermissionDeniedException(const QString &message, const QString &mimeType=u"application/json"_s, 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