Skip to content

Commit ffb5e75

Browse files
Ondrej RafajOndrej Rafaj
authored andcommitted
adding not found to the get request
1 parent 9732d11 commit ffb5e75

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Sources/S3.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public enum Error: Swift.Error {
3737
case missingBucketName
3838
case badStringData
3939
case missingData
40+
case notFound
4041
}
4142

4243

@@ -194,19 +195,26 @@ public class S3 {
194195
*/
195196
public func get(fileAtPath filePath: String, bucketName: String? = nil) throws -> Data {
196197
let fileUrl: URL? = try self.buildUrl(bucketName: bucketName, fileName: filePath)
198+
197199
guard let url = fileUrl else {
198200
throw Error.invalidUrl
199201
}
200202

201203
let headers: [String: String] = try signer.authHeaderV4(httpMethod: .get, urlString: url.absoluteString, headers: [:], payload: .none)
202204
let result: Response = try BasicClient.get(fileUrl!.absoluteString, headers: self.vaporHeaders(headers))
205+
206+
if result.status == .notFound {
207+
throw Error.notFound
208+
}
209+
203210
guard result.status == .ok else {
204211
throw Error.badResponse(result)
205212
}
206213

207214
guard let bytes: Bytes = result.body.bytes else {
208215
throw Error.missingData
209216
}
217+
210218
let data: Data = Data.init(bytes: bytes)
211219

212220
return data

0 commit comments

Comments
 (0)