handleResponse method

dynamic handleResponse(
  1. int statusCode,
  2. String body
)

Parses the body and returns a Map of the decoded json. If the statusCode is not 200, then a MandrillException is thrown.

Implementation

dynamic handleResponse(int statusCode, String body) {
  if (statusCode != 200) {
    MandrillException error;
    try {
      final errorArchive =
          KeyedArchive.unarchive(jsonDecode(body) as Map<String, dynamic>);
      final errorResponse = ErrorResponse()..decode(errorArchive);

      error = MandrillException.fromError(errorResponse);
    } catch (e) {
      _log.warning(
          'The body returned by Mandrill could not be parsed properly: $e');
      error = InvalidResponseException(body);
    }
    throw error;
  }

  return jsonDecode(body);
}