Skip to content
Permalink
Browse files

Auto format message for missing parameter

  • Loading branch information
pblottiere committed Mar 27, 2019
1 parent c5817cb commit f5171b810d154950984c7463f056f18c8cd13171
@@ -21,6 +21,7 @@

#include "qgsmodule.h"
#include "qgsdxfwriter.h"
#include "qgswmsserviceexception.h"
#include "qgswmsgetcapabilities.h"
#include "qgswmsgetmap.h"
#include "qgswmsgetstyles.h"
@@ -19,6 +19,7 @@
* *
***************************************************************************/
#include "qgswmsutils.h"
#include "qgswmsserviceexception.h"
#include "qgswmsgetlegendgraphics.h"
#include "qgswmsrenderer.h"

@@ -21,6 +21,7 @@
#include "qgswmsutils.h"
#include "qgswmsgetmap.h"
#include "qgswmsrenderer.h"
#include "qgswmsserviceexception.h"

#include <QImage>

@@ -21,6 +21,7 @@
#include "qgswmsutils.h"
#include "qgswmsgetprint.h"
#include "qgswmsrenderer.h"
#include "qgswmsserviceexception.h"

namespace QgsWms
{
@@ -18,6 +18,7 @@
#include "qgswmsparameters.h"
#include "qgsdatasourceuri.h"
#include "qgsmessagelog.h"
#include "qgswmsserviceexception.h"

const QString EXTERNAL_LAYER_PREFIX = QStringLiteral( "EXTERNAL_WMS:" );

@@ -23,7 +23,6 @@
#include <QColor>

#include "qgsrectangle.h"
#include "qgswmsserviceexception.h"
#include "qgslegendsettings.h"
#include "qgsprojectversion.h"
#include "qgsogcutils.h"
@@ -131,12 +131,12 @@ namespace QgsWms
{
// check parameters
if ( mWmsParameters.allLayersNickname().isEmpty() )
throw QgsBadRequestException( QStringLiteral( "LayerNotSpecified" ),
QStringLiteral( "LAYER is mandatory for GetLegendGraphic operation" ) );
throw QgsBadRequestException( QgsServiceException::QGIS_MISSING_PARAMETER_VALUE,
QgsWmsParameter::LAYER );

if ( mWmsParameters.format() == QgsWmsParameters::Format::NONE )
throw QgsBadRequestException( QStringLiteral( "FormatNotSpecified" ),
QStringLiteral( "FORMAT is mandatory for GetLegendGraphic operation" ) );
throw QgsBadRequestException( QgsServiceException::QGIS_MISSING_PARAMETER_VALUE,
QgsWmsParameter::FORMAT );

// get layers
std::unique_ptr<QgsLayerRestorer> restorer;
@@ -269,8 +269,8 @@ namespace QgsWms
const QString templateName = mWmsParameters.composerTemplate();
if ( templateName.isEmpty() )
{
throw QgsBadRequestException( QStringLiteral( "ParameterMissing" ),
QStringLiteral( "The TEMPLATE parameter is required for the GetPrint request" ) );
throw QgsBadRequestException( QgsServiceException::QGIS_MISSING_PARAMETER_VALUE,
QgsWmsParameter::TEMPLATE );
}

// check template
@@ -854,8 +854,8 @@ namespace QgsWms
// The QUERY_LAYERS parameter is Mandatory
if ( mWmsParameters.queryLayersNickname().isEmpty() )
{
QString msg = QObject::tr( "QUERY_LAYERS parameter is required for GetFeatureInfo" );
throw QgsBadRequestException( QStringLiteral( "LayerNotDefined" ), msg );
throw QgsBadRequestException( QgsServiceException::QGIS_MISSING_PARAMETER_VALUE,
QgsWmsParameter::QUERY_LAYERS );
}

// The I/J parameters are Mandatory if they are not replaced by X/Y or FILTER or FILTER_GEOM
@@ -866,8 +866,12 @@ namespace QgsWms

if ( !ijDefined && !xyDefined && !filtersDefined && !filterGeomDefined )
{
throw QgsBadRequestException( QStringLiteral( "ParameterMissing" ),
QStringLiteral( "I/J parameters are required for GetFeatureInfo" ) );
QgsWmsParameter::Name name = QgsWmsParameter::I;

if ( mWmsParameters.j().isEmpty() )
name = QgsWmsParameter::J;

throw QgsBadRequestException( QgsServiceException::QGIS_MISSING_PARAMETER_VALUE, name );
}

const QgsWmsParameters::Format infoFormat = mWmsParameters.infoFormat();
@@ -22,6 +22,7 @@
#include <QMetaEnum>

#include "qgsserverexception.h"
#include "qgswmsparameters.h"

namespace QgsWms
{
@@ -89,7 +90,45 @@ namespace QgsWms
: QgsServiceException( formatCode( code ), message, QString(), responseCode )
{}

QgsServiceException( ExceptionCode code, QgsWmsParameter::Name name, int responseCode )
: QgsServiceException( formatCode( code ), formatMessage( code, name ), QString(), responseCode )
{}

private:
static QString formatMessage( ExceptionCode code, QgsWmsParameter::Name parameter )
{
QString message;

const QString name = QgsWmsParameter::name( parameter );

switch ( code )
{
case QgsServiceException::QGIS_MISSING_PARAMETER_VALUE:
{
message = QStringLiteral( "The %1 parameter is missing." ).arg( name );
break;
}
case OGC_INVALID_FORMAT:
case OGC_INVALID_SRS:
case OGC_LAYER_NOT_DEFINED:
case OGC_STYLE_NOT_DEFINED:
case OGC_LAYER_NOT_QUERYABLE:
case OGC_CURRENT_UPDATE_SEQUENCE:
case OGC_INVALID_UPDATE_SEQUENCE:
case OGC_MISSING_DIMENSION_VALUE:
case OGC_INVALID_DIMENSION_VALUE:
case OGC_INVALID_CRS:
case OGC_OPERATION_NOT_SUPPORTED:
case QGIS_INVALID_PARAMETER_VALUE:
case QGIS_ERROR:
{
break;
}
}

return message;
}

static QString formatCode( ExceptionCode code )
{
// get key as a string from enum
@@ -156,6 +195,10 @@ namespace QgsWms
QgsBadRequestException( ExceptionCode code, const QString &message )
: QgsServiceException( code, message, 400 )
{}

QgsBadRequestException( ExceptionCode code, QgsWmsParameter::Name parameter )
: QgsServiceException( code, parameter, 400 )
{}
};
} // namespace QgsWms

0 comments on commit f5171b8

Please sign in to comment.
You can’t perform that action at this time.