QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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:
128 QgsBadRequestException( const QString &code, const QString &message, const QString &locator = QString() )
130 {}
131};
132#endif
133
134#ifndef SIP_RUN // No API exceptions for SIP, see python/server/qgsserverexception.sip
135
146class SERVER_EXPORT QgsServerApiException : public QgsServerException
147{
148 public:
150 QgsServerApiException( const QString &code, const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 200 )
151 : QgsServerException( message, responseCode )
152 , mCode( code )
153 , mMimeType( mimeType )
154 {
155 }
156
157 QByteArray formatResponse( QString &responseFormat SIP_OUT ) const override
158 {
159 responseFormat = mMimeType;
160 const json data {
161 {
162 { "code", mCode.toStdString() },
163 { "description", what().toStdString() },
164 }
165 };
166
167 return QByteArray::fromStdString( data.dump() );
168 }
169
170 private:
171 QString mCode;
172 QString mMimeType;
173};
174
175
187{
188 public:
190 QgsServerApiInternalServerError( const QString &message = QStringLiteral( "Internal server error" ), const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 500 )
191 : QgsServerApiException( QStringLiteral( "Internal server error" ), message, mimeType, responseCode )
192 {
193 }
194};
195
196
208{
209 public:
211 QgsServerApiNotFoundError( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 404 )
212 : QgsServerApiException( QStringLiteral( "API not found error" ), message, mimeType, responseCode )
213 {
214 }
215};
216
217
229{
230 public:
232 QgsServerApiBadRequestException( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 400 )
233 : QgsServerApiException( QStringLiteral( "Bad request error" ), message, mimeType, responseCode )
234 {
235 }
236};
237
238
250{
251 public:
253 QgsServerApiPermissionDeniedException( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 403 )
254 : QgsServerApiException( QStringLiteral( "Forbidden" ), message, mimeType, responseCode )
255 {
256 }
257};
258
270{
271 public:
273 QgsServerApiImproperlyConfiguredException( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 500 )
274 : QgsServerApiException( QStringLiteral( "Improperly configured error" ), message, mimeType, responseCode )
275 {
276 }
277};
278
279
291{
292 public:
294 QgsServerApiNotImplementedException( const QString &message = QStringLiteral( "Requested method is not implemented" ), const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 500 )
295 : QgsServerApiException( QStringLiteral( "Not implemented error" ), message, mimeType, responseCode )
296 {
297 }
298};
299
300
311{
312 public:
314 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 )
315 : QgsServerApiException( QStringLiteral( "Invalid mime-type" ), message, mimeType, responseCode )
316 {
317 }
318};
319#endif // no API exceptions for SIP
320
321#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