We do a lot of image processing in Google Cloud Functions using NodeJS and Sharp (libvips) library. Even though we have the memory limit for our functions set to 2Gb the function occasionally runs out of memory and crashes with the 'Error: memory limit exceeded. Function invocation was interrupted.' message.
Is there a way to catch this exception? I want to return a more polite (json) response so my server knows what the problem was.