Improve error handling in FileHandler

This commit is contained in:
Simon Detheridge 2019-12-23 15:58:03 +00:00
parent 27aaff7843
commit a216be5fd3

View file

@ -7,7 +7,12 @@ const FileConverter = require('./FileConverter')
const KeyBuilder = require('./KeyBuilder') const KeyBuilder = require('./KeyBuilder')
const async = require('async') const async = require('async')
const ImageOptimiser = require('./ImageOptimiser') const ImageOptimiser = require('./ImageOptimiser')
const { WriteError, ReadError, ConversionError } = require('./Errors') const {
WriteError,
ReadError,
ConversionError,
NotFoundError
} = require('./Errors')
module.exports = { module.exports = {
insertFile, insertFile,
@ -66,16 +71,17 @@ function getDirectorySize(bucket, projectId, callback) {
logger.log({ bucket, project_id: projectId }, 'getting project size') logger.log({ bucket, project_id: projectId }, 'getting project size')
PersistorManager.directorySize(bucket, projectId, function(err, size) { PersistorManager.directorySize(bucket, projectId, function(err, size) {
if (err) { if (err) {
logger.err({ bucket, project_id: projectId }, 'error getting size') return callback(
err = new ReadError('error getting project size').withCause(err) new ReadError('error getting project size').withCause(err)
)
} }
return callback(err, size) callback(null, size)
}) })
} }
function _getStandardFile(bucket, key, opts, callback) { function _getStandardFile(bucket, key, opts, callback) {
PersistorManager.getFileStream(bucket, key, opts, function(err, fileStream) { PersistorManager.getFileStream(bucket, key, opts, function(err, fileStream) {
if (err && err.name !== 'NotFoundError') { if (err && !(err instanceof NotFoundError)) {
logger.err( logger.err(
{ bucket, key, opts: _scrubSecrets(opts) }, { bucket, key, opts: _scrubSecrets(opts) },
'error getting fileStream' 'error getting fileStream'