QGIS API Documentation 3.99.0-Master (d270888f95f)
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 "qgsserverexception.h"
22#include "qgswmsparameters.h"
23
24#include <QMetaEnum>
25#include <QString>
26
27using namespace Qt::StringLiterals;
28
29namespace QgsWms
30{
31
38 {
39 Q_GADGET
40
41 public:
64 Q_ENUM( ExceptionCode )
65
66
73 QgsServiceException( const QString &code, const QString &message, const QString &locator = QString(), int responseCode = 200 )
75 {}
76
83 QgsServiceException( const QString &code, const QString &message, int responseCode )
84 : QgsOgcServiceException( code, message, QString(), responseCode, u"1.3.0"_s )
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 = u"The %1 parameter is missing."_s.arg( name );
120 break;
121 }
123 {
124 message = u"The %1 parameter is invalid."_s.arg( name );
125 break;
126 }
128 {
129 message = u"The format '%1' from %2 is not supported."_s.arg( parameter.toString(), name );
130 break;
131 }
132 case OGC_InvalidSRS:
133 {
134 message = u"The SRS is not valid."_s;
135 break;
136 }
137 case OGC_InvalidCRS:
138 {
139 message = u"The CRS is not valid."_s;
140 break;
141 }
143 {
144 message = u"The layer '%1' does not exist."_s.arg( parameter.toString() );
145 break;
146 }
148 {
149 message = u"The layer '%1' is not queryable."_s.arg( parameter.toString() );
150 break;
151 }
152 case OGC_InvalidPoint:
153 {
154 message = u"The point '%1' from '%2' is invalid."_s.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( "OGC_"_L1, QString() );
179 key.replace( "QGIS_"_L1, QString() );
180
181 return key;
182 }
183 };
184
191 {
192 public:
199 QgsSecurityException( const QString &message, const QString &locator = QString() )
200 : QgsServiceException( u"Security"_s, message, locator, 403 )
201 {}
202 };
203
210 {
211 public:
221
229 : QgsServiceException( code, parameter, 400 )
230 {}
231 };
232} // namespace QgsWms
233
234#endif
QString locator() const
Returns the locator.
QString message() const
Returns the exception message.
QString code() const
Returns the exception code.
QgsOgcServiceException(const QString &code, const QString &message, const QString &locator=QString(), int responseCode=200, const QString &version=u"1.3.0"_s)
Construction.
int responseCode() const
Returns the return HTTP response code associated with this exception.
QString toString(bool defaultValue=false) const
Converts the parameter into a string.
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).
QgsSecurityException(const QString &message, const QString &locator=QString())
Constructor for QgsSecurityException (HTTP error code 403 with Security code name).
QgsServiceException(ExceptionCode code, const QgsWmsParameter &parameter, int responseCode)
Constructor for QgsServiceException (empty locator attribute).
QgsServiceException(const QString &code, const QString &message, const QString &locator=QString(), int responseCode=200)
Constructor for QgsServiceException.
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.