fromJson static method

InfluxDBException fromJson(
  1. String errorBody,
  2. int statusCode,
  3. Map<String, String> headers
)

Implementation

static InfluxDBException fromJson(
    String errorBody, int statusCode, Map<String, String> headers) {
  String? code;
  String? message;
  dynamic body;
  try {
    body = json.decode(errorBody);
  } catch (e) {
    message = errorBody;
  }
  var retryAfter = -1;
  if (headers[HttpHeaders.retryAfterHeader] != null) {
    try {
      retryAfter = int.parse(headers[HttpHeaders.retryAfterHeader]!);
    } on FormatException {
      //ignore
    }
  }
  if (body != null) {
    if (body['message'] != null) {
      message = body['message'].toString();
    }
    if (body['code'] != null) {
      code = body['code'].toString();
    }
  }
  return InfluxDBException(statusCode, code, message, retryAfter: retryAfter);
}