github the-guild-org/apollo-angular apollo-angular@14.0.0

4 hours ago

Major Changes

  • #2395
    4e9f107
    Thanks @JesseZomer! - BREAKING CHANGE: HTTP errors now return
    Apollo Client's ServerError instead of Angular's HttpErrorResponse

    When Apollo Server returns non-2xx HTTP status codes (status >= 300), apollo-angular's HTTP links
    now return ServerError from @apollo/client/errors instead of Angular's HttpErrorResponse.
    This enables proper error detection in errorLinks using ServerError.is(error) and provides
    consistent error handling with Apollo Client's ecosystem.

    Migration Guide:

    Before:

    import { HttpErrorResponse } from '@angular/common/http';
    
    link.request(operation).subscribe({
      error: err => {
        if (err instanceof HttpErrorResponse) {
          console.log(err.status);
          console.log(err.error);
        }
      },
    });

    After:

    import { ServerError } from '@apollo/client/errors';
    
    link.request(operation).subscribe({
      error: err => {
        if (ServerError.is(err)) {
          console.log(err.statusCode);
          console.log(err.bodyText);
          console.log(err.response.headers);
        }
      },
    });

    Properties Changed:

    • err.statuserr.statusCode
    • err.errorerr.bodyText (always string, JSON stringified for objects)
    • err.headers (Angular HttpHeaders) → err.response.headers (native Headers)
    • Access response via err.response which includes: status, statusText, ok, url, type,
      redirected

    Note: This only affects HTTP-level errors (status >= 300). Network errors and other error
    types remain unchanged. GraphQL errors in the response body are still processed normally through
    Apollo Client's error handling.

    Fixes #2394

Patch Changes

  • #2392
    8d2be64
    Thanks @vz-tl! - Allow headers type in DefaultContext to be Record or
    HttpHeaders

Don't miss a new apollo-angular release

NewReleases is sending notifications on new releases.