File tree 2 files changed +15
-19
lines changed
2 files changed +15
-19
lines changed Original file line number Diff line number Diff line change @@ -217,34 +217,30 @@ class ApiSingleton {
217
217
}
218
218
}
219
219
220
- Future <dynamic > createSession (Session session) async {
220
+ Future <int ? > createSession (Session session) async {
221
221
try {
222
222
final response = await http
223
223
.post (Uri .parse ('$serverUrl $sessions ' ),
224
224
headers: headers,
225
225
body: json.encode (
226
226
session.toJson (),
227
227
))
228
- .timeout (
229
- Duration (seconds: _timeoutTimerInSeconds),
230
- onTimeout: () {
231
- print ('Request timed out' );
232
- return Future .error ('Request timed out' );
233
- },
234
- );
235
- ;
236
-
237
- if (response.statusCode != 201 ) {
238
- print (
239
- 'Request: ${response .request .toString ()} -> Response: ${response .body }' );
240
- return ApiResponse .fromJson (json.decode (response.body));
228
+ .timeout (Duration (seconds: _timeoutTimerInSeconds));
229
+ if (response.statusCode == 201 ) {
230
+ var body = json.decode (response.body);
231
+ return body['id' ] as int ;
232
+ } else {
233
+ print ("Error: Unexpected response code ${response .statusCode }" );
234
+ print ("Response body: ${response .body }" );
241
235
}
242
-
243
- var body = json.decode (response.body);
244
- return body['id' ];
236
+ } on TimeoutException {
237
+ print ("Error: Request timed out." );
238
+ } on http.ClientException catch (e) {
239
+ print ("HTTP Client Exception: $e " );
245
240
} catch (e) {
246
- return null ;
241
+ print ( "Error : ${ e }" ) ;
247
242
}
243
+ return null ;
248
244
}
249
245
250
246
Future <dynamic > closeSession (Session session) async {
Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ class Utils {
101
101
session! .id = await ApiSingleton ().createSession (session! );
102
102
}
103
103
104
- if (session! .id != null ) {
104
+ if (session? .id != null ) {
105
105
var lang = await UserManager .getLanguage ();
106
106
var userUUID = await UserManager .getUUID ();
107
107
report = Report (
You can’t perform that action at this time.
0 commit comments