- my $handle_error = sub {
- my $resp = shift;
-
- my $data = eval { $self->json->decode($resp->{content}) };
- if ($@) {
- my $content = $resp->{content} // 'No content';
- my $reason = $resp->{reason} // '';
- $data = {
- errors => [
- {
- message => "HTTP transport returned $resp->{status} ($reason): $content",
- },
- ],
- };
- }
-
- return ($data, 'graphql', $resp);
- };
- my $handle_response = sub {
- my $resp = shift;
-
- return $handle_error->($resp) if !$resp->{success};
- my $data = eval { $self->json->decode($resp->{content}) };
- if (my $err = $@) {
- warn $err if $ENV{GRAPHQL_CLIENT_DEBUG};
- $data = {
- errors => [
- {
- message => 'HTTP transport failed to decode response from GraphQL server.',
+ if (eval { $resp->isa('Future') }) {
+ return $resp->followed_by(sub {
+ my $f = shift;
+
+ if (my ($exception, $category, @other) = $f->failure) {
+ if (ref $exception eq 'HASH') {
+ my $resp = $exception;
+ return Future->done($self->_handle_error($resp));
+ }
+
+ return Future->done({
+ error => $exception,
+ response => undef,
+ details => {
+ exception_details => [$category, @other],