ServerException class

A non-2xx response from the server.

When the peer sent a structured error envelope — {"error": {"code": ..., "message": ...}}, which HttpError produces — code, reason and details carry it. When it did not, they are null and only statusCode and body are available, so a plain-text or third-party peer behaves exactly as before.

try {
  await client.users.get(id: 1);
} on ServerException catch (e) {
  if (e.code == 'user_not_found') { ... }
}
Implemented types

Constructors

ServerException({required String message, required int statusCode, String? body, String? code, String? reason, Map<String, dynamic>? details})
const
ServerException.fromBody({required String message, required int statusCode, String? body})
Builds from a raw response body, reading the error envelope when present.
factory

Properties

body → String?
The raw body, always available.
final
code → String?
The peer's stable error identifier, when it sent one.
final
details → Map<String, dynamic>?
Extra machine-readable context the peer attached.
final
hashCode → int
The hash code for this object.
no setterinherited
isStructured → bool
Whether the peer sent a structured error envelope.
no setter
message → String
The HTTP reason phrase.
final
reason → String?
The peer's human-readable explanation, when it sent one.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
statusCode → int
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited