Skip to content

Commit

Permalink
Server: throw exception in GetMap if DB connection is not ok
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jan 17, 2019
1 parent 8757853 commit 0f3c39d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions python/core/auto_generated/layout/qgslayoutitemmap.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
8 changes: 8 additions & 0 deletions src/core/layout/qgslayoutitemmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions src/core/layout/qgslayoutitemmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/server/qgsfcgiserverrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/server/services/wms/qgswmsrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
class QgsCoordinateReferenceSystem;
class QgsPrintLayout;
class QgsFeature;
class QgsLayout;
class QgsMapLayer;
class QgsMapSettings;
class QgsPointXY;
Expand Down Expand Up @@ -284,6 +285,8 @@ namespace QgsWms

void removeTemporaryLayers();

void handlePrintErrors( const QgsLayout *layout );

private:

const QgsWmsParameters &mWmsParameters;
Expand Down

0 comments on commit 0f3c39d

Please sign in to comment.