Skip to content

Commit

Permalink
Add whole parameter in exception to format message
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Mar 28, 2019
1 parent 86e9818 commit daa5e42
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
10 changes: 10 additions & 0 deletions src/server/services/wms/qgswmsparameters.cpp
Expand Up @@ -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>() );
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/server/services/wms/qgswmsparameters.h
Expand Up @@ -283,6 +283,8 @@ namespace QgsWms
*/
void raiseError() const;

QString name() const;

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

virtual ~QgsWmsParameters() = default;

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

/**
* Dumps parameters.
*/
Expand Down
32 changes: 16 additions & 16 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 9 additions & 6 deletions src/server/services/wms/qgswmsserviceexception.h
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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 )
{}
};
Expand Down

0 comments on commit daa5e42

Please sign in to comment.