ProductionCSIDResponse.fromJson constructor

ProductionCSIDResponse.fromJson(
  1. int statusCode,
  2. Map<String, dynamic> json
)

Parses JSON into the appropriate model based on status code and JSON structure.

  • statusCode: HTTP response code.
  • json: JSON body of the response.

Implementation

factory ProductionCSIDResponse.fromJson(
    int statusCode, Map<String, dynamic> json) {
  CSIDResponseStatus status = _getStatus(statusCode);

  if (status == CSIDResponseStatus.success && json.containsKey('requestID')) {
    return ProductionCSIDResponse(
      statusCode: statusCode,
      status: status,
      successData: ProductionCSIDSuccessData.fromJson(json),
    );
  } else if (status == CSIDResponseStatus.clientError &&
      json.containsKey('errors')) {
    return ProductionCSIDResponse(
      statusCode: statusCode,
      status: status,
      errorData: ProductionCSIDErrorData.fromJson(json),
    );
  } else if (status == CSIDResponseStatus.serverError &&
      json.containsKey('code') &&
      json.containsKey('message')) {
    return ProductionCSIDResponse(
      statusCode: statusCode,
      status: status,
      failureData: ProductionCSIDFailureData.fromJson(json),
    );
  } else {
    return ProductionCSIDResponse(
      statusCode: statusCode,
      status: CSIDResponseStatus.unknown,
    );
  }
}