QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 
27 namespace QgsWms
28 {
29 
37  {
38  Q_GADGET
39 
40  public:
41 
48  {
58  OGC_InvalidPoint, // new in WMS 1.3.0
59  OGC_InvalidCRS, // new in WMS 1.3.0
60  OGC_OperationNotSupported, // new in WMS 1.3.0
63  };
64  Q_ENUM( ExceptionCode )
65 
66 
73  QgsServiceException( const QString &code, const QString &message, const QString &locator = QString(),
74  int responseCode = 200 )
75  : QgsOgcServiceException( code, message, locator, responseCode, QStringLiteral( "1.3.0" ) )
76  {}
77 
84  QgsServiceException( const QString &code, const QString &message, int responseCode )
85  : QgsOgcServiceException( code, message, QString(), responseCode, QStringLiteral( "1.3.0" ) )
86  {}
87 
96  : QgsServiceException( formatCode( code ), message, QString(), responseCode )
97  {}
98 
107  : QgsServiceException( formatCode( code ), formatMessage( code, parameter ), QString(), responseCode )
108  {}
109 
110  private:
111  static QString formatMessage( ExceptionCode code, const QgsWmsParameter &parameter )
112  {
113  const QString name = parameter.name();
114  QString message;
115 
116  switch ( code )
117  {
119  {
120  message = QStringLiteral( "The %1 parameter is missing." ).arg( name );
121  break;
122  }
124  {
125  message = QStringLiteral( "The %1 parameter is invalid." ).arg( name );
126  break;
127  }
128  case OGC_InvalidFormat:
129  {
130  message = QStringLiteral( "The format '%1' from %2 is not supported." ).arg( parameter.toString(), name );
131  break;
132  }
133  case OGC_InvalidSRS:
134  {
135  message = QStringLiteral( "The SRS is not valid." );
136  break;
137  }
138  case OGC_InvalidCRS:
139  {
140  message = QStringLiteral( "The CRS is not valid." );
141  break;
142  }
143  case OGC_LayerNotDefined:
144  {
145  message = QStringLiteral( "The layer '%1' does not exist." ).arg( parameter.toString() );
146  break;
147  }
149  {
150  message = QStringLiteral( "The layer '%1' is not queryable." ).arg( parameter.toString() );
151  break;
152  }
153  case OGC_InvalidPoint:
154  {
155  message = QStringLiteral( "The point '%1' from '%2' is invalid." ).arg( parameter.toString(), name );
156  break;
157  }
158  case OGC_StyleNotDefined:
164  {
165  break;
166  }
167  }
168 
169  return message;
170  }
171 
172  static QString formatCode( ExceptionCode code )
173  {
174  // get key as a string from enum
175  const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServiceException::ExceptionCode>() );
176  QString key = metaEnum.valueToKey( code );
177 
178  // remove prefix
179  key.replace( QLatin1String( "OGC_" ), QString() );
180  key.replace( QLatin1String( "QGIS_" ), QString() );
181 
182  return key;
183  }
184  };
185 
193  {
194  public:
195 
202  QgsSecurityException( const QString &message, const QString &locator = QString() )
203  : QgsServiceException( QStringLiteral( "Security" ), message, locator, 403 )
204  {}
205  };
206 
214  {
215  public:
216 
224  : QgsServiceException( code, message, 400 )
225  {}
226 
234  : QgsServiceException( code, parameter, 400 )
235  {}
236  };
237 } // namespace QgsWms
238 
239 #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.