Skip to content
Permalink
Browse files

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

  • Loading branch information
mhugent committed Jan 15, 2019
1 parent 4ea42fa commit 8757853b17f6e6800994e7fc6b27da708bf8439d
@@ -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;
@@ -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 );

@@ -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 );
}
@@ -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 );
@@ -47,8 +47,9 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresFeatureSource
mIsTransactionConnection = true;
}

if ( !mConn )
if ( !mConn || mConn->PQstatus() != CONNECTION_OK )
{
mValid = false;
mClosed = true;
iteratorClosed();
return;
@@ -66,6 +66,8 @@ namespace QgsWms
renderJob.waitForFinished();
*image = renderJob.renderedImage();
mPainter.reset( new QPainter( image ) );

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

@@ -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
@@ -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;
};


@@ -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;

0 comments on commit 8757853

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