Skip to content
Permalink
Browse files

Auto format message for invalid parameter value

  • Loading branch information
pblottiere committed Mar 27, 2019
1 parent bdda371 commit 0f0438f6752450551e16ed731f2f8f5cd52a6acd
Showing with 25 additions and 14 deletions.
  1. +20 −13 src/server/services/wms/qgswmsrenderer.cpp
  2. +5 −1 src/server/services/wms/qgswmsserviceexception.h
@@ -278,14 +278,14 @@ namespace QgsWms
QgsPrintLayout *sourceLayout( dynamic_cast<QgsPrintLayout *>( lManager->layoutByName( templateName ) ) );
if ( !sourceLayout )
{
throw QgsBadRequestException( QStringLiteral( "InvalidTemplate" ),
QStringLiteral( "Template '%1' is not known" ).arg( templateName ) );
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QgsWmsParameter::TEMPLATE );
}

// Check that layout has at least one page
if ( sourceLayout->pageCollection()->pageCount() < 1 )
{
throw QgsBadRequestException( QStringLiteral( "InvalidTemplate" ),
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QStringLiteral( "Template '%1' has no pages" ).arg( templateName ) );
}

@@ -747,7 +747,7 @@ namespace QgsWms
// check size
if ( !checkMaximumWidthHeight() )
{
throw QgsBadRequestException( QStringLiteral( "Size error" ),
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QStringLiteral( "The requested map size is too large" ) );
}

@@ -954,8 +954,8 @@ namespace QgsWms
QgsRectangle mapExtent = mWmsParameters.bboxAsRectangle();
if ( !mWmsParameters.bbox().isEmpty() && mapExtent.isEmpty() )
{
throw QgsBadRequestException( QStringLiteral( "InvalidParameterValue" ),
QStringLiteral( "Invalid BBOX parameter" ) );
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QgsWmsParameter::BBOX );
}

QString crs = mWmsParameters.crs();
@@ -983,9 +983,15 @@ namespace QgsWms
}
}

if ( width <= 0 || height <= 0 )
if ( width <= 0 )
{
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QgsWmsParameter::WIDTH );
}
else if ( height <= 0 )
{
throw QgsException( QStringLiteral( "createImage: Invalid width / height parameters" ) );
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QgsWmsParameter::HEIGHT );
}

std::unique_ptr<QImage> image;
@@ -1032,7 +1038,8 @@ namespace QgsWms
QgsRectangle mapExtent = mWmsParameters.bboxAsRectangle();
if ( !mWmsParameters.bbox().isEmpty() && mapExtent.isEmpty() )
{
throw QgsBadRequestException( QStringLiteral( "InvalidParameterValue" ), QStringLiteral( "Invalid BBOX parameter" ) );
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QgsWmsParameter::BBOX );
}

QString crs = mWmsParameters.crs();
@@ -2806,12 +2813,12 @@ namespace QgsWms
contentBasedLegend = true;
contentBasedLegendExtent = mWmsParameters.bboxAsRectangle();
if ( contentBasedLegendExtent.isEmpty() )
throw QgsBadRequestException( QStringLiteral( "InvalidParameterValue" ),
QStringLiteral( "Invalid BBOX parameter" ) );
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QgsWmsParameter::BBOX );

if ( !mWmsParameters.rule().isEmpty() )
throw QgsBadRequestException( QStringLiteral( "InvalidParameterValue" ),
QStringLiteral( "BBOX parameter cannot be combined with RULE" ) );
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QStringLiteral( "BBOX parameter cannot be combined with RULE." ) );
}

// build layer tree
@@ -108,6 +108,11 @@ namespace QgsWms
message = QStringLiteral( "The %1 parameter is missing." ).arg( name );
break;
}
case QGIS_INVALID_PARAMETER_VALUE:
{
message = QStringLiteral( "The %1 parameter is invalid." ).arg( name );
break;
}
case OGC_INVALID_FORMAT:
case OGC_INVALID_SRS:
case OGC_LAYER_NOT_DEFINED:
@@ -119,7 +124,6 @@ namespace QgsWms
case OGC_INVALID_DIMENSION_VALUE:
case OGC_INVALID_CRS:
case OGC_OPERATION_NOT_SUPPORTED:
case QGIS_INVALID_PARAMETER_VALUE:
case QGIS_ERROR:
{
break;

0 comments on commit 0f0438f

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