QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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 <QString>
23#include <QByteArray>
24
25#include "qgsexception.h"
26#include "qgis_server.h"
27#include "qgis_sip.h"
28#include "nlohmann/json.hpp"
29
30#ifndef SIP_RUN
31using namespace nlohmann;
32#endif
33
34
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
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(),
91 int responseCode = 200, const QString &version = QStringLiteral( "1.3.0" ) );
92
94 QString message() const { return mMessage; }
95
97 QString code() const { return mCode; }
98
100 QString locator() const { return mLocator; }
101
103 QString version() const { return mVersion; }
104
105 QByteArray formatResponse( QString &responseFormat SIP_OUT ) const override;
106
107 private:
108 QString mCode;
109 QString mMessage;
110 QString mLocator;
111 QString mVersion;
112};
113
120#ifndef SIP_RUN
122{
123 public:
124
131 QgsBadRequestException( const QString &code, const QString &message, const QString &locator = QString() )
132 : QgsOgcServiceException( code, message, locator, 400 )
133 {}
134};
135#endif
136
137#ifndef SIP_RUN // No API exceptions for SIP, see python/server/qgsserverexception.sip
138
149class SERVER_EXPORT QgsServerApiException: public QgsServerException
150{
151 public:
153 QgsServerApiException( const QString &code, const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 200 )
154 : QgsServerException( message, responseCode )
155 , mCode( code )
156 , mMimeType( mimeType )
157 {
158 }
159
160 QByteArray formatResponse( QString &responseFormat SIP_OUT ) const override
161 {
162 responseFormat = mMimeType;
163 const json data
164 {
165 {
166 { "code", mCode.toStdString() },
167 { "description", what().toStdString() },
168 }
169 };
170
171 return QByteArray::fromStdString( data.dump() );
172 }
173
174 private:
175 QString mCode;
176 QString mMimeType;
177};
178
179
191{
192 public:
194 QgsServerApiInternalServerError( const QString &message = QStringLiteral( "Internal server error" ), const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 500 )
195 : QgsServerApiException( QStringLiteral( "Internal server error" ), message, mimeType, responseCode )
196 {
197 }
198};
199
200
212{
213 public:
215 QgsServerApiNotFoundError( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 404 )
216 : QgsServerApiException( QStringLiteral( "API not found error" ), message, mimeType, responseCode )
217 {
218 }
219};
220
221
233{
234 public:
236 QgsServerApiBadRequestException( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 400 )
237 : QgsServerApiException( QStringLiteral( "Bad request error" ), message, mimeType, responseCode )
238 {
239 }
240};
241
242
254{
255 public:
257 QgsServerApiPermissionDeniedException( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 403 )
258 : QgsServerApiException( QStringLiteral( "Forbidden" ), message, mimeType, responseCode )
259 {
260 }
261};
262
274{
275 public:
277 QgsServerApiImproperlyConfiguredException( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 500 )
278 : QgsServerApiException( QStringLiteral( "Improperly configured error" ), message, mimeType, responseCode )
279 {
280 }
281};
282
283
295{
296 public:
298 QgsServerApiNotImplementedException( const QString &message = QStringLiteral( "Requested method is not implemented" ), const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 500 )
299 : QgsServerApiException( QStringLiteral( "Not implemented error" ), message, mimeType, responseCode )
300 {
301 }
302};
303
304
315{
316 public:
318 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 )
319 : QgsServerApiException( QStringLiteral( "Invalid mime-type" ), message, mimeType, responseCode )
320 {
321 }
322};
323#endif // no API exceptions for SIP
324
325#endif
Exception thrown in case of malformed request.
QgsBadRequestException(const QString &code, const QString &message, const QString &locator=QString())
Constructor for QgsBadRequestException (HTTP error code 400).
Defines a QGIS exception class.
Definition: qgsexception.h:35
Exception base class for service exceptions.
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.
Bad request error API exception.
QgsServerApiBadRequestException(const QString &message, const QString &mimeType=QStringLiteral("application/json"), int responseCode=400)
Construction.
Exception base class for API exceptions.
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.
configuration error on the server prevents to serve the request, which would be valid otherwise.
QgsServerApiImproperlyConfiguredException(const QString &message, const QString &mimeType=QStringLiteral("application/json"), int responseCode=500)
Construction.
Internal server error API exception.
QgsServerApiInternalServerError(const QString &message=QStringLiteral("Internal server error"), const QString &mimeType=QStringLiteral("application/json"), int responseCode=500)
Construction.
the client sent an invalid mime type in the "Accept" header
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.
Not found error API exception.
QgsServerApiNotFoundError(const QString &message, const QString &mimeType=QStringLiteral("application/json"), int responseCode=404)
Construction.
this method is not yet implemented
QgsServerApiNotImplementedException(const QString &message=QStringLiteral("Requested method is not implemented"), const QString &mimeType=QStringLiteral("application/json"), int responseCode=500)
Construction.
Forbidden (permission denied) 403.
QgsServerApiPermissionDeniedException(const QString &message, const QString &mimeType=QStringLiteral("application/json"), int responseCode=403)
Construction.
Exception base class for server exceptions.
#define SIP_OUT
Definition: qgis_sip.h:58