Skip to content

Commit

Permalink
Auto format message for invalid parameter value
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Mar 28, 2019
1 parent bdda371 commit 0f0438f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
33 changes: 20 additions & 13 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -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 ) );
}

Expand Down Expand Up @@ -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" ) );
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/server/services/wms/qgswmsserviceexception.h
Expand Up @@ -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:
Expand All @@ -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;
Expand Down

0 comments on commit 0f0438f

Please sign in to comment.