Skip to content
Permalink
Browse files

Server: throw exception in GetMap if DB connection is not ok

  • Loading branch information
mhugent committed Jan 17, 2019
1 parent 8757853 commit 0f3c39deb783e2930bfed9485356f36d6e75034d
@@ -569,6 +569,7 @@ in the area of the map item covered by the item.
.. versionadded:: 3.6
%End


protected:

virtual void draw( QgsLayoutItemRenderContext &context );
@@ -1020,6 +1020,14 @@ void QgsLayoutItemMap::drawMap( QPainter *painter, const QgsRectangle &extent, Q
// with printing to printer on Windows (printing to PDF is fine though).
// Raster images were not displayed - see #10599
job.renderSynchronously();

mRenderingErrors.clear();
QgsMapRendererJob::Errors e = job.errors();
QgsMapRendererJob::Errors::const_iterator eIt = e.constBegin();
for ( ; eIt != e.constEnd(); ++eIt )
{
mRenderingErrors.append( qMakePair( eIt->layerID, eIt->message ) );
}
}

void QgsLayoutItemMap::recreateCachedImageInBackground()
@@ -511,6 +511,12 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem
*/
bool isLabelBlockingItem( QgsLayoutItem *item ) const;

/**
* @brief renderingErrors
* @return list of layer id / error message
*/
const QList< QPair< QString, QString > > &renderingErrors() const SIP_SKIP { return mRenderingErrors; }

protected:

void draw( QgsLayoutItemRenderContext &context ) override;
@@ -726,6 +732,9 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem
QStringList mBlockingLabelItemUuids;
QList< QPointer< QgsLayoutItem > > mBlockingLabelItems;

//!layer id / error message
QList< QPair< QString, QString > > mRenderingErrors;

void init();

//! Resets the item tooltip to reflect current map id
@@ -68,7 +68,7 @@ QgsFcgiServerRequest::QgsFcgiServerRequest()
}

// Store the URL before the server rewrite that could have been set in QUERY_STRING
mOriginalUrl = url;
//mOriginalUrl = url;

// OGC parameters are passed with the query string, which is normally part of
// the REQUEST_URI, we override the query string url in case it is defined
@@ -572,6 +572,15 @@ namespace QgsWms
QStringLiteral( "Output format '%1' is not supported in the GetPrint request" ).arg( formatString ) );
}

if ( atlas )
{
handlePrintErrors( atlas->layout() );
}
else
{
handlePrintErrors( layout.get() );
}

return tempOutputFile.readAll();
}

@@ -3250,4 +3259,24 @@ namespace QgsWms
std::unique_ptr<QImage> tmpImage( createImage( 1, 1, false ) );
return tmpImage->dotsPerMeterX() / 1000.0;
}

void QgsRenderer::handlePrintErrors( const QgsLayout *layout )
{
if ( !layout )
{
return;
}
QList< QgsLayoutItemMap * > mapList;
layout->layoutItems( mapList );

QList< QgsLayoutItemMap * >::const_iterator mapIt = mapList.constBegin();
for ( ; mapIt != mapList.constEnd(); ++mapIt )
{
if ( !( *mapIt )->renderingErrors().isEmpty() )
{
throw QgsServerException( QStringLiteral( "Print error" ) );
}
}
}

} // namespace QgsWms
@@ -30,6 +30,7 @@
class QgsCoordinateReferenceSystem;
class QgsPrintLayout;
class QgsFeature;
class QgsLayout;
class QgsMapLayer;
class QgsMapSettings;
class QgsPointXY;
@@ -284,6 +285,8 @@ namespace QgsWms

void removeTemporaryLayers();

void handlePrintErrors( const QgsLayout *layout );

private:

const QgsWmsParameters &mWmsParameters;

0 comments on commit 0f3c39d

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