checkSapMessageHeader method

void checkSapMessageHeader()

Implementation

void checkSapMessageHeader() {
  final headerValue = headers['sap-message'];
  String? sapMessage;

  if (headerValue is List && (headerValue?.isNotEmpty ?? false)) {
    sapMessage = headerValue!.first.toString();
  } else if (headerValue is String) {
    sapMessage = headerValue as String;
  }

  if (sapMessage?.contains('"severity":"error"') == true) {
    final msg = _parseSapMessage(sapMessage!);
    throw ApiResponseException.sapMessage(
      message: msg.message,
      additionalInfo:
          msg.additionalInfo?.isNotEmpty == true &&
                  msg.additionalInfo != 'null'
              ? msg.additionalInfo
              : null,
    );
  }
}