@@ -37,10 +37,11 @@ namespace nix {
37
37
struct S3Error : public Error
38
38
{
39
39
Aws::S3::S3Errors err;
40
+ Aws::String exceptionName;
40
41
41
42
template <typename ... Args>
42
- S3Error (Aws::S3::S3Errors err, const Args & ... args)
43
- : Error(args...), err(err) { };
43
+ S3Error (Aws::S3::S3Errors err, Aws::String exceptionName, const Args & ... args)
44
+ : Error(args...), err(err), exceptionName(exceptionName) { };
44
45
};
45
46
46
47
/* Helper: given an Outcome<R, E>, return R in case of success, or
@@ -51,6 +52,7 @@ R && checkAws(std::string_view s, Aws::Utils::Outcome<R, E> && outcome)
51
52
if (!outcome.IsSuccess ())
52
53
throw S3Error (
53
54
outcome.GetError ().GetErrorType (),
55
+ outcome.GetError ().GetExceptionName (),
54
56
fmt (
55
57
" %s: %s (request id: %s)" ,
56
58
s,
@@ -226,7 +228,13 @@ S3Helper::FileTransferResult S3Helper::getObject(
226
228
227
229
} catch (S3Error & e) {
228
230
if ((e.err != Aws::S3::S3Errors::NO_SUCH_KEY) &&
229
- (e.err != Aws::S3::S3Errors::ACCESS_DENIED)) throw ;
231
+ (e.err != Aws::S3::S3Errors::ACCESS_DENIED) &&
232
+ // Expired tokens are not really an error, more of a caching problem. Should be treated same as 403.
233
+ //
234
+ // AWS unwilling to provide a specific error type for the situation (https://github.com/aws/aws-sdk-cpp/issues/1843)
235
+ // so use this hack
236
+ (e.exceptionName != " ExpiredToken" )
237
+ ) throw ;
230
238
}
231
239
232
240
auto now2 = std::chrono::steady_clock::now ();
@@ -334,6 +342,10 @@ struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStore
334
342
auto & error = res.GetError ();
335
343
if (error.GetErrorType () == Aws::S3::S3Errors::RESOURCE_NOT_FOUND
336
344
|| error.GetErrorType () == Aws::S3::S3Errors::NO_SUCH_KEY
345
+ // Expired tokens are not really an error, more of a caching problem. Should be treated same as 403.
346
+ // AWS unwilling to provide a specific error type for the situation (https://github.com/aws/aws-sdk-cpp/issues/1843)
347
+ // so use this hack
348
+ || (error.GetErrorType () == Aws::S3::S3Errors::UNKNOWN && error.GetExceptionName () == " ExpiredToken" )
337
349
// If bucket listing is disabled, 404s turn into 403s
338
350
|| error.GetErrorType () == Aws::S3::S3Errors::ACCESS_DENIED)
339
351
return false ;
0 commit comments