QGIS API Documentation 3.41.0-Master (cea29feecf2)
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(), int responseCode = 200, const QString &version = QStringLiteral( "1.3.0" ) );
89
91 QString message() const { return mMessage; }
92
94 QString code() const { return mCode; }
95
97 QString locator() const { return mLocator; }
98
100 QString version() const { return mVersion; }
101
102 QByteArray formatResponse( QString &responseFormat SIP_OUT ) const override;
103
104 private:
105 QString mCode;
106 QString mMessage;
107 QString mLocator;
108 QString mVersion;
109};
110
117#ifndef SIP_RUN
119{
120 public:
127 QgsBadRequestException( const QString &code, const QString &message, const QString &locator = QString() )
128 : QgsOgcServiceException( code, message, locator, 400 )
129 {}
130};
131#endif
132
133#ifndef SIP_RUN // No API exceptions for SIP, see python/server/qgsserverexception.sip
134
145class SERVER_EXPORT QgsServerApiException : public QgsServerException
146{
147 public:
149 QgsServerApiException( const QString &code, const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 200 )
150 : QgsServerException( message, responseCode )
151 , mCode( code )
152 , mMimeType( mimeType )
153 {
154 }
155
156 QByteArray formatResponse( QString &responseFormat SIP_OUT ) const override
157 {
158 responseFormat = mMimeType;
159 const json data {
160 {
161 { "code", mCode.toStdString() },
162 { "description", what().toStdString() },
163 }
164 };
165
166 return QByteArray::fromStdString( data.dump() );
167 }
168
169 private:
170 QString mCode;
171 QString mMimeType;
172};
173
174
186{
187 public:
189 QgsServerApiInternalServerError( const QString &message = QStringLiteral( "Internal server error" ), const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 500 )
190 : QgsServerApiException( QStringLiteral( "Internal server error" ), message, mimeType, responseCode )
191 {
192 }
193};
194
195
207{
208 public:
210 QgsServerApiNotFoundError( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 404 )
211 : QgsServerApiException( QStringLiteral( "API not found error" ), message, mimeType, responseCode )
212 {
213 }
214};
215
216
228{
229 public:
231 QgsServerApiBadRequestException( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 400 )
232 : QgsServerApiException( QStringLiteral( "Bad request error" ), message, mimeType, responseCode )
233 {
234 }
235};
236
237
249{
250 public:
252 QgsServerApiPermissionDeniedException( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 403 )
253 : QgsServerApiException( QStringLiteral( "Forbidden" ), message, mimeType, responseCode )
254 {
255 }
256};
257
269{
270 public:
272 QgsServerApiImproperlyConfiguredException( const QString &message, const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 500 )
273 : QgsServerApiException( QStringLiteral( "Improperly configured error" ), message, mimeType, responseCode )
274 {
275 }
276};
277
278
290{
291 public:
293 QgsServerApiNotImplementedException( const QString &message = QStringLiteral( "Requested method is not implemented" ), const QString &mimeType = QStringLiteral( "application/json" ), int responseCode = 500 )
294 : QgsServerApiException( QStringLiteral( "Not implemented error" ), message, mimeType, responseCode )
295 {
296 }
297};
298
299
310{
311 public:
313 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 )
314 : QgsServerApiException( QStringLiteral( "Invalid mime-type" ), message, mimeType, responseCode )
315 {
316 }
317};
318#endif // no API exceptions for SIP
319
320#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