onRequest method
Called when the request is about to be sent.
Implementation
@override
Future<dynamic> onRequest(
RequestOptions options,
RequestInterceptorHandler handler,
) async {
try {
// Loads the JSON data from assets
final jsonData = await getJsonFromAssets(
'${MocksPaths.mockPathBaseAssets}${options.path}.json',
);
// Resolves the request with the loaded JSON data
handler.resolve(Response(requestOptions: options, data: jsonData));
} catch (e) {
// Rejects the request with a mock error
handler.reject(DioException(
requestOptions: options,
type: DioExceptionType.unknown,
error: MocksPaths.error,
));
}
}