On certain pages of my site, I download and display resized (using the Imager plugin) images from remote site.

Now, sometimes that remote site returns error and in such case Imager is throwing exceptions, blocking the whole page from being viewed.

Now, is there a way to suppress server errors when possible, e.g. write them to log file and don't stop page processing?

devMode is set to false.

  • 1
    What errors are you getting? – RitterKnight Mar 28 '16 at 16:33
  • Telling image can't be resized (related to the fact that the remote server does not return 404 code but merely showing 'not found' page) – Yuri Salimovskiy Mar 31 '16 at 15:46

It depends on the type of errors that are being thrown. If they are Twig/template errors, then you can can set the suppressTemplateErrors config setting to true and they will simply get logged and the page request will continue as usual.

If they are non-Twig exceptions, then you'd have to do something more fancy like make a plugin that's essentially a facade for the Imager plugin and wraps all of it's calls in a try/catch block that just swallows any exceptions.

Or make a pull request that added support for it to the plugin itself.

  • Good idea about creating a wrapper. I'll try that, thanks @Brad Bell – Yuri Salimovskiy Mar 31 '16 at 15:46
  • Ended up modifying Imager and submitting pull request – Yuri Salimovskiy Apr 1 '16 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.