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 Exception(
      [
        msg.message,
        if (msg.additionalInfo?.isNotEmpty == true &&
            msg.additionalInfo != 'null')
          msg.additionalInfo,
      ].join('\n\n'),
    );
  }
}