AuthFailureMatcher class Auth Failures
Decides whether a GraphQL failure means the server rejected the tokens.
A failure arrives on one of two channels: an error event, such as a
ServerException for an HTTP 401, or a Response whose errors carry an
auth code, such as extensions.code: "UNAUTHENTICATED" in an HTTP 200. The
link replays a request only when this class says the tokens were rejected,
so a wrong rule either misses a rejection or replays a request that was
never about the tokens.
Extend this class to recognise other failures, for example the
HttpLinkParserException that HttpLink emits for a 401 whose body is not
GraphQL JSON:
final class AppAuthFailureMatcher extends AuthFailureMatcher {
const AppAuthFailureMatcher();
@override
bool isAuthError(Object error) =>
(error is HttpLinkParserException &&
error.response.statusCode == 401) ||
super.isAuthError(error);
}
Constructors
-
AuthFailureMatcher({Set<
int> statusCodes = const {401}, Set<String> errorCodes = const {'UNAUTHENTICATED'}}) -
Creates a matcher for the HTTP
statusCodesof aServerExceptionand theerrorCodesinerrors[].extensions.codeof aResponse.const
Properties
-
errorCodes
→ Set<
String> -
The
extensions.codevalues that mean the tokens were rejected.final - hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
statusCodes
→ Set<
int> -
The HTTP status codes that mean the tokens were rejected.
final
Methods
-
isAuthError(
Object error) → bool -
Whether the error event
errormeans the tokens were rejected. -
isAuthResponse(
Response response) → bool -
Whether one of the
errorsofresponsemeans the tokens were rejected. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited