Skip to content
Permalink
Browse files

Add whole parameter in exception to format message

  • Loading branch information
pblottiere committed Mar 28, 2019
1 parent 86e9818 commit daa5e428397d271644c804fe76904c4448d88264
@@ -185,6 +185,11 @@ namespace QgsWms
return val;
}

QString QgsWmsParameter::name() const
{
return QgsWmsParameter::name( mName );
}

QString QgsWmsParameter::name( const QgsWmsParameter::Name name )
{
const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameter::Name>() );
@@ -537,6 +542,11 @@ namespace QgsWms
}
}

QgsWmsParameter QgsWmsParameters::operator[]( QgsWmsParameter::Name name ) const
{
return mWmsParameters[name];
}

bool QgsWmsParameters::loadParameter( const QString &key, const QString &value )
{
bool loaded = false;
@@ -283,6 +283,8 @@ namespace QgsWms
*/
void raiseError() const;

QString name() const;

/**
* Converts a parameter's name into its string representation.
*/
@@ -350,6 +352,8 @@ namespace QgsWms

virtual ~QgsWmsParameters() = default;

QgsWmsParameter operator[]( QgsWmsParameter::Name name ) const;

/**
* Dumps parameters.
*/
@@ -132,11 +132,11 @@ namespace QgsWms
// check parameters
if ( mWmsParameters.allLayersNickname().isEmpty() )
throw QgsBadRequestException( QgsServiceException::QGIS_MISSING_PARAMETER_VALUE,
QgsWmsParameter::LAYERS );
mWmsParameters[QgsWmsParameter::LAYERS] );

if ( mWmsParameters.format() == QgsWmsParameters::Format::NONE )
throw QgsBadRequestException( QgsServiceException::QGIS_MISSING_PARAMETER_VALUE,
QgsWmsParameter::FORMAT );
mWmsParameters[QgsWmsParameter::FORMAT] );

// get layers
std::unique_ptr<QgsLayerRestorer> restorer;
@@ -279,7 +279,7 @@ namespace QgsWms
if ( !sourceLayout )
{
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QgsWmsParameter::TEMPLATE );
mWmsParameters[QgsWmsParameter::TEMPLATE ] );
}

// Check that layout has at least one page
@@ -511,8 +511,8 @@ namespace QgsWms
}
else //unknown format
{
throw QgsBadRequestException( QStringLiteral( "InvalidFormat" ),
QStringLiteral( "Output format '%1' is not supported in the GetPrint request" ).arg( mWmsParameters.formatAsString() ) );
throw QgsBadRequestException( QgsServiceException::OGC_INVALID_FORMAT,
mWmsParameters[QgsWmsParameter::FORMAT] );
}

if ( atlas )
@@ -853,7 +853,7 @@ namespace QgsWms
if ( mWmsParameters.queryLayersNickname().isEmpty() )
{
throw QgsBadRequestException( QgsServiceException::QGIS_MISSING_PARAMETER_VALUE,
QgsWmsParameter::QUERY_LAYERS );
mWmsParameters[QgsWmsParameter::QUERY_LAYERS] );
}

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

if ( !ijDefined && !xyDefined && !filtersDefined && !filterGeomDefined )
{
QgsWmsParameter::Name name = QgsWmsParameter::I;
QgsWmsParameter parameter = mWmsParameters[QgsWmsParameter::I];

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

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

const QgsWmsParameters::Format infoFormat = mWmsParameters.infoFormat();
if ( infoFormat == QgsWmsParameters::Format::NONE )
{
throw QgsBadRequestException( QStringLiteral( "InvalidFormat" ),
QStringLiteral( "Invalid INFO_FORMAT parameter" ) );
throw QgsBadRequestException( QgsServiceException::OGC_INVALID_FORMAT,
mWmsParameters[QgsWmsParameter::INFO_FORMAT] );
}

// create the mapSettings and the output image
@@ -953,7 +953,7 @@ namespace QgsWms
if ( !mWmsParameters.bbox().isEmpty() && mapExtent.isEmpty() )
{
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QgsWmsParameter::BBOX );
mWmsParameters[QgsWmsParameter::BBOX] );
}

QString crs = mWmsParameters.crs();
@@ -984,12 +984,12 @@ namespace QgsWms
if ( width <= 0 )
{
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QgsWmsParameter::WIDTH );
mWmsParameters[QgsWmsParameter::WIDTH] );
}
else if ( height <= 0 )
{
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QgsWmsParameter::HEIGHT );
mWmsParameters[QgsWmsParameter::HEIGHT] );
}

std::unique_ptr<QImage> image;
@@ -1037,7 +1037,7 @@ namespace QgsWms
if ( !mWmsParameters.bbox().isEmpty() && mapExtent.isEmpty() )
{
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QgsWmsParameter::BBOX );
mWmsParameters[QgsWmsParameter::BBOX] );
}

QString crs = mWmsParameters.crs();
@@ -2808,7 +2808,7 @@ namespace QgsWms
contentBasedLegendExtent = mWmsParameters.bboxAsRectangle();
if ( contentBasedLegendExtent.isEmpty() )
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QgsWmsParameter::BBOX );
mWmsParameters[QgsWmsParameter::BBOX] );

if ( !mWmsParameters.rule().isEmpty() )
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
@@ -90,17 +90,16 @@ namespace QgsWms
: QgsServiceException( formatCode( code ), message, QString(), responseCode )
{}

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

private:
static QString formatMessage( ExceptionCode code, QgsWmsParameter::Name parameter )
static QString formatMessage( ExceptionCode code, const QgsWmsParameter &parameter )
{
const QString name = parameter.name();
QString message;

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

switch ( code )
{
case QgsServiceException::QGIS_MISSING_PARAMETER_VALUE:
@@ -114,6 +113,10 @@ namespace QgsWms
break;
}
case OGC_INVALID_FORMAT:
{
message = QStringLiteral( "The format %1 from %2 is not supported." ).arg( parameter.toString(), name );
break;
}
case OGC_INVALID_SRS:
case OGC_LAYER_NOT_DEFINED:
case OGC_STYLE_NOT_DEFINED:
@@ -200,7 +203,7 @@ namespace QgsWms
: QgsServiceException( code, message, 400 )
{}

QgsBadRequestException( ExceptionCode code, QgsWmsParameter::Name parameter )
QgsBadRequestException( ExceptionCode code, const QgsWmsParameter &parameter )
: QgsServiceException( code, parameter, 400 )
{}
};

0 comments on commit daa5e42

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