Turns what an HTTP call did into the adapter's own signal.
This is where one server's conventions stop and the contract begins, and it is the only place in a REST adapter that reads a status code. Everything downstream sees a Fault carrying a signal, so swapping one REST backend for another is a matter of writing another classifier, another set of tables, and nothing else.
Pylon supplies none of it, not even the obvious half. status >= 400 looks
universal until it meets the API that answers 200 with an error payload, or
the one where 404 is an ordinary answer meaning the resource is simply not
there yet. Both exist, and both are entitled to say so here.
class AdminClassifier implements RestClassifier<AdminSignal> {
const AdminClassifier();
@override
AdminSignal? ofResponse(RestResponse response) {
if (response.status >= 200 && response.status < 300) return null;
final body = response.body;
final code = body is Map<String, dynamic> ? body['code'] : null;
if (code == 'vpn_required') return AdminSignal.vpnRequired;
if (code == 'name_empty') return AdminSignal.nameEmpty;
return switch (response.status) {
401 => AdminSignal.unauthorized,
403 => AdminSignal.forbidden,
404 => AdminSignal.notFound,
409 => AdminSignal.statusConflict,
429 => AdminSignal.tooManyRequests,
_ => AdminSignal.unknown,
};
}
@override
AdminSignal ofTransport(Object error, StackTrace stackTrace) =>
error is TimeoutException ? AdminSignal.timedOut : AdminSignal.noRoute;
}
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
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
ofResponse(
RestResponse response) → S? -
The signal
responseamounts to, ornullwhen it was a success. -
ofTransport(
Object error, StackTrace stackTrace) → S - The signal for a call that never got an answer.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited