-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into release/chopper_generator/v7.1.0
# Conflicts: # chopper/lib/src/annotations.dart # chopper/lib/src/http_logging_interceptor.dart # chopper/lib/src/interceptor.dart # chopper/lib/src/request.dart # chopper/lib/src/response.dart # chopper/test/ensure_build_test.dart # chopper/test/test_service.chopper.dart # chopper/test/test_service.dart # chopper/test/test_service_variable.chopper.dart # chopper/test/test_service_variable.dart # chopper_generator/lib/src/generator.dart # chopper_generator/lib/src/vars.dart # chopper_generator/test/ensure_build_test.dart # chopper_generator/test/test_service.chopper.dart # chopper_generator/test/test_service.dart # chopper_generator/test/test_service_variable.chopper.dart # chopper_generator/test/test_service_variable.dart # faq.md
- Loading branch information
Showing
28 changed files
with
2,556 additions
and
97 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:chopper/src/response.dart'; | ||
|
||
/// An exception thrown when a [Response] is unsuccessful < 200 or > 300. | ||
class ChopperHttpException implements Exception { | ||
ChopperHttpException(this.response); | ||
|
||
final Response response; | ||
|
||
@override | ||
String toString() { | ||
return 'Could not fetch the response for ${response.base.request}. Status code: ${response.statusCode}, error: ${response.error}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:chopper/src/chopper_http_exception.dart'; | ||
import 'package:chopper/src/response.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
test('ChopperHttpException toString prints available information', () { | ||
final request = http.Request('GET', Uri.parse('http://localhost:8000')); | ||
final base = http.Response('Foobar', 400, request: request); | ||
final response = Response(base, 'Foobar', error: 'FooError'); | ||
|
||
final exception = ChopperHttpException(response); | ||
|
||
final result = exception.toString(); | ||
|
||
expect( | ||
result, | ||
'Could not fetch the response for GET http://localhost:8000. Status code: 400, error: FooError', | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class FooErrorType { | ||
const FooErrorType(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import 'package:chopper/src/chopper_http_exception.dart'; | ||
import 'package:chopper/src/response.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:test/test.dart'; | ||
|
||
import 'fixtures/error_fixtures.dart'; | ||
|
||
void main() { | ||
group('Response error casting test', () { | ||
test('Response is succesfull, [returns null]', () { | ||
final base = http.Response('Foobar', 200); | ||
|
||
final response = Response(base, 'Foobar'); | ||
|
||
final result = response.errorWhereType<FooErrorType>(); | ||
|
||
expect(result, isNull); | ||
}); | ||
|
||
test('Response is unsuccessful and has no error object, [returns null]', | ||
() { | ||
final base = http.Response('Foobar', 400); | ||
|
||
final response = Response(base, ''); | ||
|
||
final result = response.errorWhereType<FooErrorType>(); | ||
|
||
expect(result, isNull); | ||
}); | ||
|
||
test( | ||
'Response is unsuccessful and has error object of different type, [returns null]', | ||
() { | ||
final base = http.Response('Foobar', 400); | ||
|
||
final response = Response(base, '', error: 'Foobar'); | ||
|
||
final result = response.errorWhereType<FooErrorType>(); | ||
|
||
expect(result, isNull); | ||
}); | ||
|
||
test( | ||
'Response is unsuccessful and has error object of specified type, [returns error as ErrorType]', | ||
() { | ||
final base = http.Response('Foobar', 400); | ||
|
||
final response = Response(base, 'Foobar', error: FooErrorType()); | ||
|
||
final result = response.errorWhereType<FooErrorType>(); | ||
|
||
expect(result, isNotNull); | ||
expect(result, isA<FooErrorType>()); | ||
}); | ||
}); | ||
|
||
group('bodyOrThrow tests', () { | ||
test('Response is successful and has body, [bodyOrThrow returns body]', () { | ||
final base = http.Response('Foobar', 200); | ||
final response = Response(base, {'Foo': 'Bar'}); | ||
|
||
final result = response.bodyOrThrow; | ||
|
||
expect(result, isNotNull); | ||
expect(result, {'Foo': 'Bar'}); | ||
}); | ||
|
||
test( | ||
'Response is unsuccessful and has Exception as error, [bodyOrThrow throws error]', | ||
() { | ||
final base = http.Response('Foobar', 400); | ||
final response = Response(base, '', error: Exception('Error occurred')); | ||
|
||
expect(() => response.bodyOrThrow, throwsA(isA<Exception>())); | ||
}); | ||
|
||
test( | ||
'Response is unsuccessful and has non-exception object as error, [bodyOrThrow throws error]', | ||
() { | ||
final base = http.Response('Foobar', 400); | ||
final response = Response(base, '', error: 'Error occurred'); | ||
|
||
expect(() => response.bodyOrThrow, throwsA(isA<ChopperHttpException>())); | ||
}); | ||
|
||
test( | ||
'Response is unsuccessful and has no error, [bodyOrThrow throws ChopperHttpException]', | ||
() { | ||
final base = http.Response('Foobar', 400); | ||
final response = Response(base, ''); | ||
|
||
expect(() => response.bodyOrThrow, throwsA(isA<ChopperHttpException>())); | ||
}); | ||
|
||
test( | ||
'Response is successful and has no body, [bodyOrThrow throws ChopperHttpException]', | ||
() { | ||
final base = http.Response('Foobar', 200); | ||
final Response<String> response = Response(base, null); | ||
|
||
expect(() => response.bodyOrThrow, throwsA(isA<ChopperHttpException>())); | ||
}); | ||
|
||
test('Response is successful and has void body, [bodyOrThrow returns void]', | ||
() { | ||
final base = http.Response('Foobar', 200); | ||
// Ignoring void checks for testing purposes | ||
//ignore: void_checks | ||
final Response<void> response = Response(base, ''); | ||
|
||
expect(() => response.bodyOrThrow, returnsNormally); | ||
}); | ||
}); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.