Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save codelynx/ccca513a3c35597594e6d4efe1dc98d0 to your computer and use it in GitHub Desktop.
Save codelynx/ccca513a3c35597594e6d4efe1dc98d0 to your computer and use it in GitHub Desktop.
// AWS-SDK-Swift
//
// When you need to find if error is caused by resource not found,rather than other type of errors
// such as network error or access permissions related error. This is how to find, if this error
// is cause of resource not found.
//
// Note:
// I don't want to spend time for this next time, so I paste code snippet here for my future reference
func processHeadRequest(s3client: S3Client, bucket: String, key: String) async throws {
do {
let result: HeadObjectOutputResponse = try await self.s3Client.headObject(input: HeadObjectInput(bucket: bucket, key: key))
_ = result
}
catch {
switch error {
case let error1 as ClientRuntime.SdkError<AWSS3.HeadObjectOutputError>:
switch error1 {
case .client(let error2, _):
switch error2 {
case .retryError(let error3):
switch error3 {
case let error4 as SdkError<HeadObjectOutputError>:
switch error4 {
case .service(let error5, _):
switch error5 {
case .notFound(_):
// code for not found
return
default:
break
}
default:
break
}
break
default:
break
}
default:
break
}
default:
break
}
default:
break
}
throw error
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment