utils/client/helpers/settle library

A utility class for handling and settling HTTP responses in a standardized way.

The Settle class provides static methods to parse, validate, and extract information from HTTP responses, including error handling and optional authentication expiration triggers. It is designed to be configured globally and used throughout your application to ensure consistent response handling.

Example usage:

Settle.configure(
  onForceOut: () {
    // Handle forced logout or session expiration
  },
  errorMessageExtractor: (response) {
    // Custom error message extraction logic
    return "Custom error: $response";
  },
);

final result = Settle.settleResponse<MyModel>(
  responseString,
  fromJsonT: (json) => MyModel.fromJson(json),
  wrapper: (json) => MyModel.fromJson(json),
);

Typedefs:

Methods:

  • configure sets up global callbacks and error extractors.
  • settleResponse parses and validates the response, returning the wrapped result or throwing a FinnUtilsSettlerException on error.
  • _triggerForceOutIfNeeded checks for authentication expiration and triggers the callback if needed.
  • _defaultErrorMessageExtractor provides a default way to extract error messages from responses.
  • _safeJsonDecode safely decodes a JSON string into a map.

Throws:

See also:

Classes

Settle

Typedefs

ErrorMessageExtractor = String Function(String? responseString)
FromJson<T> = T Function(dynamic json)
OnForceOutCallback = void Function()
ResponseWrapper<T> = T Function(Map<String, dynamic> json)