Skip to content

Commit

Permalink
Update search endpoint to return response
Browse files Browse the repository at this point in the history
  • Loading branch information
abraham committed Jan 19, 2023
1 parent 4c6d20e commit abd3d18
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/src/endpoints/search.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dart:convert';

import '../authentication.dart';
import '../exception.dart';
import '../model.dart';
import '../model_response.dart';
import '../models/results.dart';
import '../utilities.dart';

Expand All @@ -9,7 +12,10 @@ mixin Search on Authentication, Utilities {
///
/// - authenticated
/// - read read:search
Future<Results> search(String q, {bool resolve = false}) async {
Future<ModelResponse<Results>> search(
String q, {
bool resolve = false,
}) async {
final response = await request(
Method.get,
"/api/v2/search",
Expand All @@ -20,6 +26,21 @@ mixin Search on Authentication, Utilities {
},
);

return Results.fromJson(json.decode(response.body));
try {
return ModelResponse(
Model.success(
Results.fromJson(json.decode(response.body)),
),
);
} on Exception catch (e) {
return ModelResponse(
Model.failure(
ModelException(
exception: e,
unparsed: response.body,
),
),
);
}
}
}

0 comments on commit abd3d18

Please sign in to comment.