ResponseRule class abstract

Decides how a response went from its body, for backends that answer 200 to everything and put the real result in a field:

TidyDioInterceptor(rules: [
  ResponseRule.field('success', {true: HttpOutcome.success, false: HttpOutcome.error}, message: 'message'),
  ResponseRule.field('response_type', {
    'SUCCESS': HttpOutcome.success,
    'WARNING': HttpOutcome.warning,
    'ERROR': HttpOutcome.error,
  }, message: 'messages'),
])

Rules only change how the call is logged (colour, level, verdict). They never change what Dio does: nothing is thrown and the response is left alone. The first rule that returns a verdict wins.

Constructors

ResponseRule()
const
ResponseRule.custom(RuleVerdict? decide(Response response), {bool when(RequestOptions request)?})
Your own logic. Return null to leave the call to the next rule.
factory
ResponseRule.field(String path, Map<Object?, HttpOutcome> values, {String? message, HttpOutcome? otherwise, bool when(RequestOptions request)?})
Looks up path (dotted, such as meta.status or errors.0.code) in the JSON body and maps its value through values.
factory

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

evaluate(Response response) → RuleVerdict?
The verdict for response, or null when this rule has no opinion.
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