getStructuredError method

Future<StructuredError?> getStructuredError()

Returns the last structured error (message, SQLSTATE, native code), or null if there is no error.

Implementation

Future<StructuredError?> getStructuredError() async {
  final r = await _sendRequest<StructuredErrorResponse>(
    GetStructuredErrorRequest(_nextRequestId()),
  );
  if (r.error != null) return null;
  if (r.message.isEmpty && r.sqlStateString == null) return null;
  final sqlState = (r.sqlStateString ?? '').codeUnits;
  return StructuredError(
    message: r.message,
    sqlState: sqlState.isNotEmpty ? sqlState : List.filled(5, 0),
    nativeCode: r.nativeCode ?? 0,
  );
}