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 15, 2019
1 parent 4ea42fa commit 8757853
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/core/qgsmaprendererjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct LayerRenderJob
bool cached; // if true, img already contains cached image from previous rendering
QgsWeakMapLayerPointer layer;
int renderingTime; //!< Time it took to render the layer in ms (it is -1 if not rendered or still rendering)
QStringList errors; //! rendering errors
};

typedef QList<LayerRenderJob> LayerRenderJobs;
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsmaprendererparalleljob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ void QgsMapRendererParallelJob::renderLayersFinished()
{
Q_ASSERT( mStatus == RenderingLayers );

LayerRenderJobs::const_iterator it = mLayerJobs.constBegin();
for ( ; it != mLayerJobs.constEnd(); ++it )
{
if ( !it->errors.isEmpty() )
{
mErrors.append( Error( it->layer->id(), it->errors.join( ',' ) ) );
}
}

// compose final image
mFinalImage = composeImage( mSettings, mLayerJobs, mLabelJob );

Expand Down Expand Up @@ -269,6 +278,8 @@ void QgsMapRendererParallelJob::renderLayerStatic( LayerRenderJob &job )
{
QgsDebugMsg( QStringLiteral( "Caught unhandled unknown exception" ) );
}

job.errors = job.renderer->errors();
job.renderingTime += t.elapsed();
QgsDebugMsgLevel( QStringLiteral( "job %1 end [%2 ms] (layer %3)" ).arg( reinterpret_cast< quint64 >( &job ), 0, 16 ).arg( job.renderingTime ).arg( job.layer ? job.layer->id() : QString() ), 2 );
}
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsvectorlayerrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ bool QgsVectorLayerRenderer::render()
else
drawRenderer( fit );

if ( !fit.isValid() )
{
mErrors.append( QStringLiteral( "Data source invalid" ) );
}

if ( usingEffect )
{
mRenderer->paintEffect()->end( mContext );
Expand Down
3 changes: 2 additions & 1 deletion src/providers/postgres/qgspostgresfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresFeatureSource
mIsTransactionConnection = true;
}

if ( !mConn )
if ( !mConn || mConn->PQstatus() != CONNECTION_OK )
{
mValid = false;
mClosed = true;
iteratorClosed();
return;
Expand Down
19 changes: 19 additions & 0 deletions src/server/services/wms/qgsmaprendererjobproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ namespace QgsWms
renderJob.waitForFinished();
*image = renderJob.renderedImage();
mPainter.reset( new QPainter( image ) );

getRenderErrors( &renderJob );
}
else
{
Expand All @@ -75,6 +77,7 @@ namespace QgsWms
renderJob.setFeatureFilterProvider( mFeatureFilterProvider );
#endif
renderJob.renderSynchronously();
getRenderErrors( &renderJob );
}
}

Expand All @@ -83,4 +86,20 @@ namespace QgsWms
return mPainter.release();
}

void QgsMapRendererJobProxy::getRenderErrors( const QgsMapRendererJob *job )
{
if ( !job )
{
return;
}

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

} // namespace qgsws
7 changes: 7 additions & 0 deletions src/server/services/wms/qgsmaprendererjobproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ namespace QgsWms
*/
QPainter *takePainter();

const QList< QPair< QString, QString > > &errors() const { return mErrors; }

private:
bool mParallelRendering;
QgsFeatureFilterProvider *mFeatureFilterProvider = nullptr;
std::unique_ptr<QPainter> mPainter;

void getRenderErrors( const QgsMapRendererJob *job );

//! Layer id / error message
QList< QPair< QString, QString > > mErrors;
};


Expand Down
11 changes: 11 additions & 0 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2917,6 +2917,17 @@ namespace QgsWms
QgsMapRendererJobProxy renderJob( mSettings.parallelRendering(), mSettings.maxThreads(), &filters );
renderJob.render( mapSettings, &image );
painter = renderJob.takePainter();

if ( !renderJob.errors().isEmpty() )
{
QString layerWMSName;
QgsMapLayer *errorLayer = mProject->mapLayer( renderJob.errors().at( 0 ).first );
if ( errorLayer )
{
layerWMSName = layerNickname( *errorLayer );
}
throw QgsServerException( QString( "Map rendering error in layer '%1'" ).arg( layerWMSName ) );
}
}

return painter;
Expand Down

0 comments on commit 8757853

Please sign in to comment.