resolve method
Resolves the configured absolute HTTP(S) base URL.
Implementation
Uri resolve(
Map<Object?, Object?> endpoint, {
Map<String, String>? environment,
}) {
final inline = endpoint['baseUrl'];
final fromEnvironment = endpoint['baseUrlFrom'];
if (inline != null && fromEnvironment != null) {
throw const FormatException(
'Endpoint must declare exactly one of baseUrl or baseUrlFrom',
);
}
final value = inline is String
? inline
: fromEnvironment is String
? (environment ?? Platform.environment)[fromEnvironment]
: null;
if (value == null || value.trim().isEmpty) {
final name = fromEnvironment is String
? ' environment $fromEnvironment'
: '';
throw FormatException('Endpoint base URL$name is not configured');
}
final uri = Uri.tryParse(value);
if (uri == null || !uri.hasScheme || !uri.hasAuthority) {
throw FormatException('Endpoint base URL must be absolute: $value');
}
if (uri.scheme != 'http' && uri.scheme != 'https') {
throw FormatException('Endpoint base URL must use HTTP(S): $value');
}
return uri;
}