* _errorActions - take a number of actions once have error getting obj * @param {object} err - arsenal errors object * @param {string} errorDocument - key to get error document * @param {object []} routingRules - array of routingRule objects * @param {object} bucket - bucket metadata * @param {
(err, errorDocument, routingRules,
bucket, objectKey, corsHeaders, request, log, callback)
| 28 | * @return {undefined} |
| 29 | */ |
| 30 | function _errorActions(err, errorDocument, routingRules, |
| 31 | bucket, objectKey, corsHeaders, request, log, callback) { |
| 32 | const bucketName = bucket.getName(); |
| 33 | const errRoutingRule = findRoutingRule(routingRules, |
| 34 | objectKey, err.code); |
| 35 | if (errRoutingRule) { |
| 36 | // route will redirect |
| 37 | const action = request.method === 'HEAD' ? 'headObject' : 'getObject'; |
| 38 | monitoring.promMetrics( |
| 39 | request.method, bucketName, err.code, action); |
| 40 | return callback(err, false, null, corsHeaders, errRoutingRule, |
| 41 | objectKey); |
| 42 | } |
| 43 | if (request.method === 'HEAD') { |
| 44 | monitoring.promMetrics( |
| 45 | 'HEAD', bucketName, err.code, 'headObject'); |
| 46 | return callback(err, false, null, corsHeaders); |
| 47 | } |
| 48 | if (errorDocument) { |
| 49 | return metadata.getObjectMD(bucketName, errorDocument, {}, log, |
| 50 | (errObjErr, errObjMD) => { |
| 51 | if (errObjErr) { |
| 52 | // error retrieving error document so return original error |
| 53 | // and set boolean of error retrieving user's error document |
| 54 | // to true |
| 55 | monitoring.promMetrics( |
| 56 | 'GET', bucketName, err.code, 'getObject'); |
| 57 | return callback(err, true, null, corsHeaders); |
| 58 | } |
| 59 | // return the default error message if the object is private |
| 60 | // rather than sending a stored error file |
| 61 | // eslint-disable-next-line no-param-reassign |
| 62 | request.objectKey = errorDocument; |
| 63 | if (!isObjAuthorized(bucket, errObjMD, request.apiMethods || 'objectGet', |
| 64 | constants.publicId, null, log, request, request.actionImplicitDenies, true)) { |
| 65 | log.trace('errorObj not authorized', { error: err }); |
| 66 | monitoring.promMetrics( |
| 67 | 'GET', bucketName, err.code, 'getObject'); |
| 68 | return callback(err, true, null, corsHeaders); |
| 69 | } |
| 70 | const dataLocator = errObjMD.location; |
| 71 | if (errObjMD['x-amz-server-side-encryption']) { |
| 72 | for (let i = 0; i < dataLocator.length; i++) { |
| 73 | dataLocator[i].masterKeyId = |
| 74 | errObjMD['x-amz-server-side-encryption-aws-' + |
| 75 | 'kms-key-id']; |
| 76 | dataLocator[i].algorithm = |
| 77 | errObjMD['x-amz-server-side-encryption']; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | if (errObjMD['x-amz-website-redirect-location']) { |
| 82 | const redirectLocation = |
| 83 | errObjMD['x-amz-website-redirect-location']; |
| 84 | const redirectInfo = { withError: true, |
| 85 | location: redirectLocation }; |
| 86 | log.trace('redirecting to x-amz-website-redirect-location', |
| 87 | { location: redirectLocation }); |
no test coverage detected