QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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 QByteArray formatResponse( QString &responseFormat SIP_OUT ) const override
158 {
159 responseFormat = mMimeType;
160 const json data { {
161 { "code", mCode.toStdString() },
162 { "description", what().toStdString() },
163 } };
164
165 return QByteArray::fromStdString( data.dump() );
166 }
167
168 private:
169 QString mCode;
170 QString mMimeType;
171};
172
173
185{
186 public:
188 QgsServerApiInternalServerError( const QString &message = u"Internal server error"_s, const QString &mimeType = u"application/json"_s, int responseCode = 500 )
189 : QgsServerApiException( u"Internal server error"_s, message, mimeType, responseCode )
190 {}
191};
192
193
205{
206 public:
208 QgsServerApiNotFoundError( const QString &message, const QString &mimeType = u"application/json"_s, int responseCode = 404 )
209 : QgsServerApiException( u"API not found error"_s, message, mimeType, responseCode )
210 {}
211};
212
213
225{
226 public:
228 QgsServerApiBadRequestException( const QString &message, const QString &mimeType = u"application/json"_s, int responseCode = 400 )
229 : QgsServerApiException( u"Bad request error"_s, message, mimeType, responseCode )
230 {}
231};
232
233
245{
246 public:
248 QgsServerApiPermissionDeniedException( const QString &message, const QString &mimeType = u"application/json"_s, int responseCode = 403 )
249 : QgsServerApiException( u"Forbidden"_s, message, mimeType, responseCode )
250 {}
251};
252
264{
265 public:
267 QgsServerApiImproperlyConfiguredException( const QString &message, const QString &mimeType = u"application/json"_s, int responseCode = 500 )
268 : QgsServerApiException( u"Improperly configured error"_s, message, mimeType, responseCode )
269 {}
270};
271
272
284{
285 public:
287 QgsServerApiNotImplementedException( const QString &message = u"Requested method is not implemented"_s, const QString &mimeType = u"application/json"_s, int responseCode = 500 )
288 : QgsServerApiException( u"Not implemented error"_s, message, mimeType, responseCode )
289 {}
290};
291
292
303{
304 public:
307 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,
308 const QString &mimeType = u"application/json"_s,
309 int responseCode = 406
310 )
311 : QgsServerApiException( u"Invalid mime-type"_s, message, mimeType, responseCode )
312 {}
313};
314#endif // no API exceptions for SIP
315
316#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:57