Skip to content

Commit 8aa1fd9

Browse files
committed
Add rawResponse
1 parent 7d14d42 commit 8aa1fd9

6 files changed

+51
-6
lines changed

lib/src/client/response/collection_fetched.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:json_api/src/client/response.dart';
55
class CollectionFetched {
66
CollectionFetched(this.rawResponse) {
77
final document = InboundDocument(rawResponse.document ??
8-
(throw ArgumentError('The document must not be empty')));
8+
(throw FormatException('The document must not be empty')));
99
collection.addAll(document.dataAsCollection());
1010
included.addAll(document.included());
1111
meta.addAll(document.meta());

lib/src/client/response/related_resource_fetched.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:json_api/src/client/response.dart';
88
class RelatedResourceFetched {
99
RelatedResourceFetched(this.rawResponse) {
1010
final document = InboundDocument(rawResponse.document ??
11-
(throw ArgumentError('The document must not be empty')));
11+
(throw FormatException('The document must not be empty')));
1212
resource = document.dataAsResourceOrNull();
1313
included.addAll(document.included());
1414
meta.addAll(document.meta());

lib/src/client/response/relationship_fetched.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ class RelationshipFetched<R extends Relationship> {
88

99
static RelationshipFetched<ToMany> many(Response response) {
1010
final document = InboundDocument(response.document ??
11-
(throw ArgumentError('The document must not be empty')));
11+
(throw FormatException('The document must not be empty')));
1212
return RelationshipFetched(response, document.asToMany())
1313
..included.addAll(document.included());
1414
}
1515

1616
static RelationshipFetched<ToOne> one(Response response) {
1717
final document = InboundDocument(response.document ??
18-
(throw ArgumentError('The document must not be empty')));
18+
(throw FormatException('The document must not be empty')));
1919
return RelationshipFetched(response, document.asToOne())
2020
..included.addAll(document.included());
2121
}

lib/src/client/response/resource_created.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:json_api/src/client/response.dart';
99
class ResourceCreated {
1010
ResourceCreated(this.rawResponse) {
1111
final document = InboundDocument(rawResponse.document ??
12-
(throw ArgumentError('The document must not be empty')));
12+
(throw FormatException('The document must not be empty')));
1313
resource = document.dataAsResource();
1414
included.addAll(document.included());
1515
meta.addAll(document.meta());

lib/src/client/response/resource_fetched.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:json_api/src/client/response.dart';
66
class ResourceFetched {
77
ResourceFetched(this.rawResponse) {
88
final document = InboundDocument(rawResponse.document ??
9-
(throw ArgumentError('The document must not be empty')));
9+
(throw FormatException('The document must not be empty')));
1010
resource = document.dataAsResource();
1111
included.addAll(document.included());
1212
meta.addAll(document.meta());
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import 'package:http_interop/http_interop.dart' as i;
2+
import 'package:json_api/client.dart';
3+
import 'package:json_api/src/client/response.dart';
4+
import 'package:test/expect.dart';
5+
import 'package:test/scaffolding.dart';
6+
7+
void main() {
8+
final emptyResponse = Response(i.Response(200, i.Body(), i.Headers()), null);
9+
group('CollectionFetched', () {
10+
test('throws on empty body', () {
11+
expect(() => CollectionFetched(emptyResponse), throwsFormatException);
12+
});
13+
});
14+
15+
group('RelatedResourceFetched', () {
16+
test('throws on empty body', () {
17+
expect(
18+
() => RelatedResourceFetched(emptyResponse), throwsFormatException);
19+
});
20+
});
21+
22+
group('RelationshipFetched', () {
23+
test('.many() throws on empty body', () {
24+
expect(
25+
() => RelationshipFetched.many(emptyResponse), throwsFormatException);
26+
});
27+
28+
test('.one() throws on empty body', () {
29+
expect(
30+
() => RelationshipFetched.one(emptyResponse), throwsFormatException);
31+
});
32+
});
33+
34+
group('ResourceCreated', () {
35+
test('throws on empty body', () {
36+
expect(() => ResourceCreated(emptyResponse), throwsFormatException);
37+
});
38+
});
39+
40+
group('ResourceFetched', () {
41+
test('throws on empty body', () {
42+
expect(() => ResourceFetched(emptyResponse), throwsFormatException);
43+
});
44+
});
45+
}

0 commit comments

Comments
 (0)