onRequest method
Called when the request is about to be sent.
Implementation
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) async {
SafePrint("Checking SHA 256 Finger Prints...");
try {
if (allowedSHAFingerprints.isEmpty) {
SafePrint("⚠ No SHA Finger Prints provided, allowing connection...");
return handler.next(options);
}
final isValidCertificate = await _validateCertificate(options.uri.host);
if (isValidCertificate) {
SafePrint("✅ Allowed SHA Finger Prints");
return handler.next(options);
} else {
SafePrint("⚠ Error SHA Finger Prints is invalid!");
}
} catch (e) {
SafePrint(e);
throw DioException(
error: '⚠ Error validating certificate \n$e',
requestOptions: options,
response: Response(
requestOptions: options,
statusCode: 400,
),
);
}
}