client: Catch exceptions in put methods

This commit is contained in:
Elias Projahn 2020-04-26 18:31:07 +02:00
parent 9d4554b67f
commit 37a1353297

View file

@ -31,6 +31,7 @@ class MusicusClient {
/// ///
/// Returns true, if the operation was successful. /// Returns true, if the operation was successful.
Future<bool> putPerson(Person person) async { Future<bool> putPerson(Person person) async {
try {
final response = await _client.put( final response = await _client.put(
'$host/persons/${person.id}', '$host/persons/${person.id}',
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
@ -38,6 +39,9 @@ class MusicusClient {
); );
return response.statusCode == HttpStatus.ok; return response.statusCode == HttpStatus.ok;
} on Exception {
return false;
}
} }
/// Get a list of all available instruments. /// Get a list of all available instruments.
@ -58,6 +62,7 @@ class MusicusClient {
/// ///
/// Returns true, if the operation was successful. /// Returns true, if the operation was successful.
Future<bool> putInstrument(Instrument instrument) async { Future<bool> putInstrument(Instrument instrument) async {
try {
final response = await _client.put( final response = await _client.put(
'$host/instruments/${instrument.id}', '$host/instruments/${instrument.id}',
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
@ -65,6 +70,9 @@ class MusicusClient {
); );
return response.statusCode == HttpStatus.ok; return response.statusCode == HttpStatus.ok;
} on Exception {
return false;
}
} }
/// Get all works composed by the person with the ID [personId]. /// Get all works composed by the person with the ID [personId].
@ -92,6 +100,7 @@ class MusicusClient {
/// ///
/// Returns true, if the operation was successful. /// Returns true, if the operation was successful.
Future<bool> putWork(WorkInfo workInfo) async { Future<bool> putWork(WorkInfo workInfo) async {
try {
final response = await _client.put( final response = await _client.put(
'$host/works/${workInfo.work.id}', '$host/works/${workInfo.work.id}',
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
@ -99,6 +108,9 @@ class MusicusClient {
); );
return response.statusCode == HttpStatus.ok; return response.statusCode == HttpStatus.ok;
} on Exception {
return false;
}
} }
/// Get a list of all ensembles. /// Get a list of all ensembles.
@ -119,6 +131,7 @@ class MusicusClient {
/// ///
/// Returns true, if the operation was successful. /// Returns true, if the operation was successful.
Future<bool> putEnsemble(Ensemble ensemble) async { Future<bool> putEnsemble(Ensemble ensemble) async {
try {
final response = await _client.put( final response = await _client.put(
'$host/ensembles/${ensemble.id}', '$host/ensembles/${ensemble.id}',
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
@ -126,6 +139,9 @@ class MusicusClient {
); );
return response.statusCode == HttpStatus.ok; return response.statusCode == HttpStatus.ok;
} on Exception {
return false;
}
} }
/// Get a recording by ID. /// Get a recording by ID.
@ -139,6 +155,7 @@ class MusicusClient {
/// ///
/// Returns true, if the operation was successful. /// Returns true, if the operation was successful.
Future<bool> putRecording(RecordingInfo recordingInfo) async { Future<bool> putRecording(RecordingInfo recordingInfo) async {
try {
final response = await _client.put( final response = await _client.put(
'$host/recordings/${recordingInfo.recording.id}', '$host/recordings/${recordingInfo.recording.id}',
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
@ -146,6 +163,9 @@ class MusicusClient {
); );
return response.statusCode == HttpStatus.ok; return response.statusCode == HttpStatus.ok;
} on Exception {
return false;
}
} }
/// Close the internal http client. /// Close the internal http client.