import 'package:dio/dio.dart'; import 'errors/marianumconnect_error.dart'; import 'marianumconnect_api.dart'; import 'marianumconnect_endpoint.dart'; /// Shared base for MarianumConnect API queries. Owns the [dio] client (the /// shared authenticated singleton by default) and routes calls through [guard] /// so every query maps a DioException to the app's typed AppExceptions the same /// way instead of repeating the try/catch. Subclasses with bespoke error or /// lifecycle handling (own dio, silent failure, custom status mapping) may skip /// [guard] and still reuse [dio]/[endpoint]. abstract class MarianumConnectQuery { final Dio dio; MarianumConnectQuery({Dio? dio}) : dio = dio ?? MarianumConnectApi.dio(); /// Resolves [path] against the active mobile-API base URL. String endpoint(String path) => MarianumConnectEndpoint.resolve(path); /// Runs [body], converting any DioException into the matching AppException. Future guard(Future Function() body) async { try { return await body(); } on DioException catch (e) { throw mapMarianumConnectError(e); } } }