makeTPException static method

TPException makeTPException(
  1. Response? response
)

Implementation

static TPException makeTPException(Response<dynamic>? response) {
  final tpException = TPException();

  if(response?.data == null) {
    tpException.setCode(response?.statusCode);
    tpException.setMessage(response?.statusMessage);
    return tpException;
  }

  var errorCode = response?.data["code"];
  errorCode ??= response?.statusCode;
  var errorMsg = response?.data["message"];
  errorMsg ??= response?.statusMessage;

  if(errorCode is String) {
    tpException.setCode(int.parse(errorCode));
  } else {
    tpException.setCode(errorCode);
  }

  if(errorMsg is String) {
    tpException.setMessage(errorMsg);
  } else {
    tpException.setMessage(errorMsg.toString());
  }
  return tpException;
}