QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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 <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
40#ifndef SIP_RUN
41class SERVER_EXPORT QgsServerException : public QgsException
42{
43#else
44class SERVER_EXPORT QgsServerException
45{
46#endif
47 public:
49 QgsServerException( const QString &message, int responseCode = 500 );
50
54 int responseCode() const { return mResponseCode; }
55
64 virtual QByteArray formatResponse( QString &responseFormat SIP_OUT ) const;
65
66 private:
67 int mResponseCode;
68};
69
79#ifndef SIP_RUN
80class SERVER_EXPORT QgsOgcServiceException : public QgsServerException
81{
82#else
83class SERVER_EXPORT QgsOgcServiceException
84{
85#endif
86 public:
88 QgsOgcServiceException( const QString &code, const QString &message, const QString &locator = QString(),
89 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() )
130 : QgsOgcServiceException( code, message, locator, 400 )
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 {
164 { "code", mCode.toStdString() },
165 { "description", what().toStdString() },
166 }
167 };
168
169 return QByteArray::fromStdString( data.dump() );
170 }
171
172 private:
173 QString mCode;
174 QString mMimeType;
175};
176
177
189{
190 public:
192 QgsServerApiInternalServerError( const QString &message = QStringLiteral( "Internal server error" ), const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 500 )
193 : QgsServerApiException( QStringLiteral( "Internal server error" ), message, mimeType, responseCode )
194 {
195 }
196};
197
198
210{
211 public:
213 QgsServerApiNotFoundError( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 404 )
214 : QgsServerApiException( QStringLiteral( "API not found error" ), message, mimeType, responseCode )
215 {
216 }
217};
218
219
231{
232 public:
234 QgsServerApiBadRequestException( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 400 )
235 : QgsServerApiException( QStringLiteral( "Bad request error" ), message, mimeType, responseCode )
236 {
237 }
238};
239
240
252{
253 public:
255 QgsServerApiPermissionDeniedException( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 403 )
256 : QgsServerApiException( QStringLiteral( "Forbidden" ), message, mimeType, responseCode )
257 {
258 }
259};
260
272{
273 public:
275 QgsServerApiImproperlyConfiguredException( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 500 )
276 : QgsServerApiException( QStringLiteral( "Improperly configured error" ), message, mimeType, responseCode )
277 {
278 }
279};
280
281
293{
294 public:
296 QgsServerApiNotImplementedException( const QString &message = QStringLiteral( "Requested method is not implemented" ), const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 500 )
297 : QgsServerApiException( QStringLiteral( "Not implemented error" ), message, mimeType, responseCode )
298 {
299 }
300};
301
302
313{
314 public:
316 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 )
317 : QgsServerApiException( QStringLiteral( "Invalid mime-type" ), message, mimeType, responseCode )
318 {
319 }
320};
321#endif // no API exceptions for SIP
322
323#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.
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