QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgswmsserviceexception.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsserviceexception.h
3 ------------------------
4 begin : June 13, 2006
5 copyright : (C) 2006 by Marco Hugentobler
6 email : marco dot hugentobler at karto dot baug dot ethz dot ch
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 QGSWMSSERVICEEXCEPTION_H
19#define QGSWMSSERVICEEXCEPTION_H
20
21#include <QString>
22#include <QMetaEnum>
23
24#include "qgsserverexception.h"
25#include "qgswmsparameters.h"
26
27namespace QgsWms
28{
29
36 {
37 Q_GADGET
38
39 public:
40
63 Q_ENUM( ExceptionCode )
64
65
72 QgsServiceException( const QString &code, const QString &message, const QString &locator = QString(),
73 int responseCode = 200 )
74 : QgsOgcServiceException( code, message, locator, responseCode, QStringLiteral( "1.3.0" ) )
75 {}
76
83 QgsServiceException( const QString &code, const QString &message, int responseCode )
84 : QgsOgcServiceException( code, message, QString(), responseCode, QStringLiteral( "1.3.0" ) )
85 {}
86
95 : QgsServiceException( formatCode( code ), message, QString(), responseCode )
96 {}
97
106 : QgsServiceException( formatCode( code ), formatMessage( code, parameter ), QString(), responseCode )
107 {}
108
109 private:
110 static QString formatMessage( ExceptionCode code, const QgsWmsParameter &parameter )
111 {
112 const QString name = parameter.name();
113 QString message;
114
115 switch ( code )
116 {
118 {
119 message = QStringLiteral( "The %1 parameter is missing." ).arg( name );
120 break;
121 }
123 {
124 message = QStringLiteral( "The %1 parameter is invalid." ).arg( name );
125 break;
126 }
128 {
129 message = QStringLiteral( "The format '%1' from %2 is not supported." ).arg( parameter.toString(), name );
130 break;
131 }
132 case OGC_InvalidSRS:
133 {
134 message = QStringLiteral( "The SRS is not valid." );
135 break;
136 }
137 case OGC_InvalidCRS:
138 {
139 message = QStringLiteral( "The CRS is not valid." );
140 break;
141 }
143 {
144 message = QStringLiteral( "The layer '%1' does not exist." ).arg( parameter.toString() );
145 break;
146 }
148 {
149 message = QStringLiteral( "The layer '%1' is not queryable." ).arg( parameter.toString() );
150 break;
151 }
152 case OGC_InvalidPoint:
153 {
154 message = QStringLiteral( "The point '%1' from '%2' is invalid." ).arg( parameter.toString(), name );
155 break;
156 }
163 {
164 break;
165 }
166 }
167
168 return message;
169 }
170
171 static QString formatCode( ExceptionCode code )
172 {
173 // get key as a string from enum
174 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServiceException::ExceptionCode>() );
175 QString key = metaEnum.valueToKey( code );
176
177 // remove prefix
178 key.replace( QLatin1String( "OGC_" ), QString() );
179 key.replace( QLatin1String( "QGIS_" ), QString() );
180
181 return key;
182 }
183 };
184
191 {
192 public:
193
200 QgsSecurityException( const QString &message, const QString &locator = QString() )
201 : QgsServiceException( QStringLiteral( "Security" ), message, locator, 403 )
202 {}
203 };
204
211 {
212 public:
213
223
231 : QgsServiceException( code, parameter, 400 )
232 {}
233 };
234} // namespace QgsWms
235
236#endif
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 toString(bool defaultValue=false) const
Converts the parameter into a string.
Exception thrown in case of malformed request.
QgsBadRequestException(ExceptionCode code, const QgsWmsParameter &parameter)
Constructor for QgsBadRequestException (HTTP error code 400).
QgsBadRequestException(ExceptionCode code, const QString &message)
Constructor for QgsBadRequestException (HTTP error code 400).
Exception thrown when data access violates access controls.
QgsSecurityException(const QString &message, const QString &locator=QString())
Constructor for QgsSecurityException (HTTP error code 403 with Security code name).
Exception class for WMS service exceptions.
QgsServiceException(ExceptionCode code, const QgsWmsParameter &parameter, int responseCode)
Constructor for QgsServiceException (empty locator attribute).
QgsServiceException(const QString &code, const QString &message, int responseCode)
Constructor for QgsServiceException (empty locator attribute).
ExceptionCode
Exception codes as defined in OGC scpecifications for WMS 1.1.1 and WMS 1.3.0.
QgsServiceException(ExceptionCode code, const QString &message, int responseCode)
Constructor for QgsServiceException (empty locator attribute).
WMS parameter received from the client.
QString name() const
Returns the name of the parameter.
Median cut implementation.