(define-exception-type &aws-error &external-error make-aws-error aws-error?
  (code aws-error-code)
  (message aws-error-message)
  (request-id aws-error-request-id)
  (host-id aws-error-host-id))

(define-exception-type &s3-error &aws-error make-s3-error s3-error?
  (bucket s3-error-bucket)
  (endpoint s3-error-endpoint))

;;; TODO: Contribute to (aws) proper.
(define (check-s3-response response)
  "Check if the XML response contains an error code/message;
if so, raise an &s3-error exception."
  (when ((sxpath '(// Error)) response)
    (sxml-match response
                ((*TOP* ,pi
                        (Error (Code ,code)
                               (Message ,message)
                               (Endpoint ,endpoint)
                               (Bucket ,bucket)
                               (RequestId ,request-id)
                               (HostId ,host-id)))
                 (raise-exception
                  (make-s3-error code message request-id host-id
                                 bucket endpoint))))))

Generated by apteryx using scpaste at Thu Apr 16 11:04:10 2026. JST. (original)