Skip to content

Commit

Permalink
Handle error from s3 copy-to! in 200 response
Browse files Browse the repository at this point in the history
  • Loading branch information
chiefnoah committed Oct 25, 2023
1 parent d3af8be commit bb6a5aa
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/std/net/s3/api.ss
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,20 @@
(using ((self :- bucket)
(client (bucket-client self) : s3-client))
(let* ((headers [["x-amz-copy-source" :: src]])
(req (s3-request/error client
(req (s3-client::request client
verb: 'PUT
bucket: (bucket-name self)
path: (string-append "/" dest)
extra-headers: headers)))
extra-headers: headers))
(error (s3-response-error? (s3-parse-xml req))))
(request-close req)
(when error
(raise-s3-error
bucket::copy-to!
"Unable to perform server-side copy"
; when error isn't empty, it should be a parsed XML tree
(sxml-find error (sxml-e? 'Code) cadr)
(request-status-text req)))
(void)))))


Expand Down Expand Up @@ -213,12 +221,15 @@

(defrule (s3-request/error self ...)
(with-request-error
{request self ...}))
(s3-client::request self ...)))

(def (s3-parse-xml req)
(read-xml (request-content req)
namespaces: '(("http://s3.amazonaws.com/doc/2006-03-01/" . "s3"))))

(defrule (s3-response-error? xml)
(sxml-find xml (sxml-e? 'Error)))

(def (with-request-error req)
(using (req :~ request?)
(if (and (fx>= (request-status req) 200)
Expand Down

0 comments on commit bb6a5aa

Please sign in to comment.