QGIS API Documentation 3.41.0-Master (cea29feecf2)
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:
62 Q_ENUM( ExceptionCode )
63
64
71 QgsServiceException( const QString &code, const QString &message, const QString &locator = QString(), int responseCode = 200 )
72 : QgsOgcServiceException( code, message, locator, responseCode, QStringLiteral( "1.3.0" ) )
73 {}
74
81 QgsServiceException( const QString &code, const QString &message, int responseCode )
82 : QgsOgcServiceException( code, message, QString(), responseCode, QStringLiteral( "1.3.0" ) )
83 {}
84
93 : QgsServiceException( formatCode( code ), message, QString(), responseCode )
94 {}
95
104 : QgsServiceException( formatCode( code ), formatMessage( code, parameter ), QString(), responseCode )
105 {}
106
107 private:
108 static QString formatMessage( ExceptionCode code, const QgsWmsParameter &parameter )
109 {
110 const QString name = parameter.name();
111 QString message;
112
113 switch ( code )
114 {
116 {
117 message = QStringLiteral( "The %1 parameter is missing." ).arg( name );
118 break;
119 }
121 {
122 message = QStringLiteral( "The %1 parameter is invalid." ).arg( name );
123 break;
124 }
126 {
127 message = QStringLiteral( "The format '%1' from %2 is not supported." ).arg( parameter.toString(), name );
128 break;
129 }
130 case OGC_InvalidSRS:
131 {
132 message = QStringLiteral( "The SRS is not valid." );
133 break;
134 }
135 case OGC_InvalidCRS:
136 {
137 message = QStringLiteral( "The CRS is not valid." );
138 break;
139 }
141 {
142 message = QStringLiteral( "The layer '%1' does not exist." ).arg( parameter.toString() );
143 break;
144 }
146 {
147 message = QStringLiteral( "The layer '%1' is not queryable." ).arg( parameter.toString() );
148 break;
149 }
150 case OGC_InvalidPoint:
151 {
152 message = QStringLiteral( "The point '%1' from '%2' is invalid." ).arg( parameter.toString(), name );
153 break;
154 }
161 {
162 break;
163 }
164 }
165
166 return message;
167 }
168
169 static QString formatCode( ExceptionCode code )
170 {
171 // get key as a string from enum
172 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServiceException::ExceptionCode>() );
173 QString key = metaEnum.valueToKey( code );
174
175 // remove prefix
176 key.replace( QLatin1String( "OGC_" ), QString() );
177 key.replace( QLatin1String( "QGIS_" ), QString() );
178
179 return key;
180 }
181 };
182
189 {
190 public:
197 QgsSecurityException( const QString &message, const QString &locator = QString() )
198 : QgsServiceException( QStringLiteral( "Security" ), message, locator, 403 )
199 {}
200 };
201
208 {
209 public:
219
227 : QgsServiceException( code, parameter, 400 )
228 {}
229 };
230} // namespace QgsWms
231
232#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.