Skip to content

Commit

Permalink
chore: Increase timeout for getting image from pexels API
Browse files Browse the repository at this point in the history
  • Loading branch information
codekeyz committed Nov 7, 2024
1 parent 2457990 commit 855cf06
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/src/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:convert';
import 'dart:io';
import 'dart:isolate';

import 'package:http/http.dart' as http;
import 'package:pharaoh/pharaoh_next.dart';
Expand All @@ -15,8 +14,8 @@ Future<String> getRandomImage(String searchText) async {
final response = await http.get(
Uri.parse('https://api.pexels.com/v1/search?query=$searchText&per_page=1'),
headers: {HttpHeaders.authorizationHeader: env<String>('PEXELS_API_KEY', '')},
).timeout(const Duration(seconds: 2));
final result = await Isolate.run(() => jsonDecode(response.body)) as Map;
).timeout(const Duration(seconds: 5));
final result = jsonDecode(response.body) as Map;
resultingImageUrl = result['photos'][0]['src']['medium'];
} catch (error, trace) {
stderr.writeln('An error occurred while getting image for $searchText');
Expand Down

0 comments on commit 855cf06

Please sign in to comment.