settleResponse<T> static method
T
settleResponse<T>(
- String responseString, {
- required FromJson<
T> fromJsonT, - required ResponseWrapper<
T> wrapper,
Parses and validates responseString, then wraps it with wrapper.
fromJsonT: Converts the raw JSON map into an intermediate Dart object.wrapper: Produces the final return type from the JSON map.
Returns the wrapped result on success.
Throws FinnUtilsSettlerException on invalid JSON, non-2xx status, or
if _triggerForceOutIfNeeded detects session expiration.
Implementation
static T settleResponse<T>(
String responseString, {
required FromJson<T> fromJsonT,
required ResponseWrapper<T> wrapper,
}) {
try {
final Map<String, dynamic>? response = _safeJsonDecode(responseString);
_triggerForceOutIfNeeded(responseString);
if (response == null) {
throw FinnUtilsSettlerException("Invalid or empty JSON response.");
}
final int? statusCode = response["status"];
if (statusCode == null || statusCode < 200 || statusCode >= 300) {
throw FinnUtilsSettlerException(_defaultExtractor(responseString));
}
return wrapper(response);
} catch (e) {
throw FinnUtilsSettlerException(e.toString());
}
}