AzureTranslationError.fromResponse constructor

AzureTranslationError.fromResponse(
  1. Response response
)

Implementation

factory AzureTranslationError.fromResponse(http.Response response) {
  int? code;
  String? message;

  try {
    // if anyone can think of a less gross way of doing this lmk lmao
    final error = jsonDecode(response.body)['error']! as Map<String, dynamic>;
    code = error['code'];
    message = error['message'];
  } catch (_) {}

  return AzureTranslationError(
    httpCode: response.statusCode,
    code: code,
    message: message,
  );
}