Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
onTime
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
onTime InnoLab
onTime
Commits
92a83c8b
Commit
92a83c8b
authored
1 year ago
by
doodlezucc
Browse files
Options
Downloads
Patches
Plain Diff
show fetch errors in dialog
parent
9f98ef70
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/dialogs/error_dialog.dart
+20
-0
20 additions, 0 deletions
lib/dialogs/error_dialog.dart
lib/main.dart
+13
-1
13 additions, 1 deletion
lib/main.dart
lib/untis/fetch.dart
+22
-5
22 additions, 5 deletions
lib/untis/fetch.dart
with
55 additions
and
6 deletions
lib/dialogs/error_dialog.dart
0 → 100644
+
20
−
0
View file @
92a83c8b
import
'package:flutter/material.dart'
;
class
ErrorDialog
extends
StatelessWidget
{
final
String
title
;
final
Object
?
error
;
const
ErrorDialog
({
super
.
key
,
required
this
.
title
,
required
this
.
error
});
@override
Widget
build
(
BuildContext
context
)
{
return
SimpleDialog
(
title:
Text
(
title
),
children:
[
SimpleDialogOption
(
child:
Text
(
'An error occurred:
${error.runtimeType}
\n
$error
'
),
),
],
);
}
}
This diff is collapsed.
Click to expand it.
lib/main.dart
+
13
−
1
View file @
92a83c8b
import
'dart:async'
;
import
'dart:async'
;
import
'dart:io'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'branding.dart'
;
import
'branding.dart'
;
import
'context.dart'
;
import
'context.dart'
;
import
'dialogs/error_dialog.dart'
;
import
'drawer/drawer.dart'
;
import
'drawer/drawer.dart'
;
import
'timetable/timetable.dart'
;
import
'timetable/timetable.dart'
;
import
'toolbar/toolbar.dart'
;
import
'toolbar/toolbar.dart'
;
...
@@ -63,7 +65,9 @@ class _MyHomePageState extends State<MyHomePage> {
...
@@ -63,7 +65,9 @@ class _MyHomePageState extends State<MyHomePage> {
@override
@override
void
initState
()
{
void
initState
()
{
super
.
initState
();
super
.
initState
();
loadProfile
();
loadProfile
()
.
onError
((
error
,
_
)
{
_showErrorDialog
(
'Failed to connect'
,
error
);
});
}
}
@override
@override
...
@@ -74,6 +78,14 @@ class _MyHomePageState extends State<MyHomePage> {
...
@@ -74,6 +78,14 @@ class _MyHomePageState extends State<MyHomePage> {
super
.
dispose
();
super
.
dispose
();
}
}
void
_showErrorDialog
(
String
title
,
Object
?
error
)
{
stderr
.
write
(
error
);
showDialog
(
context:
context
,
builder:
(
context
)
=
>
ErrorDialog
(
title:
title
,
error:
error
),
);
}
Future
<
void
>
loadProfile
()
async
{
Future
<
void
>
loadProfile
()
async
{
final
profile
=
await
appContext
.
profile
.
firstNotNull
;
final
profile
=
await
appContext
.
profile
.
firstNotNull
;
final
classes
=
await
untis
.
allClasses
.
fetched
;
final
classes
=
await
untis
.
allClasses
.
fetched
;
...
...
This diff is collapsed.
Click to expand it.
lib/untis/fetch.dart
+
22
−
5
View file @
92a83c8b
...
@@ -84,14 +84,21 @@ class UntisFetch {
...
@@ -84,14 +84,21 @@ class UntisFetch {
final
responseString
=
await
utf8
.
decodeStream
(
response
);
final
responseString
=
await
utf8
.
decodeStream
(
response
);
final
onDownloadEnd
=
DateTime
.
now
();
final
onDownloadEnd
=
DateTime
.
now
();
final
bodyJson
=
jsonDecode
(
responseString
);
if
(
response
.
statusCode
!=
200
)
{
throw
FetchError
(
response
.
statusCode
,
responseString
);
}
final
onDecodeEnd
=
DateTime
.
now
();
try
{
final
bodyJson
=
jsonDecode
(
responseString
);
final
onDecodeEnd
=
DateTime
.
now
();
final
stats
=
final
stats
=
FetchStats
(
onStart
,
onDownloadStart
,
onDownloadEnd
,
onDecodeEnd
);
FetchStats
(
onStart
,
onDownloadStart
,
onDownloadEnd
,
onDecodeEnd
);
return
(
bodyJson
as
Json
,
resultCookies
,
stats
);
return
(
bodyJson
as
Json
,
resultCookies
,
stats
);
}
on
FormatException
catch
(
_
)
{
throw
FetchError
(
response
.
statusCode
,
responseString
);
}
}
}
Future
<
Json
>
requestOptions
(
RequestOptions
options
)
async
{
Future
<
Json
>
requestOptions
(
RequestOptions
options
)
async
{
...
@@ -148,3 +155,13 @@ class FetchStats {
...
@@ -148,3 +155,13 @@ class FetchStats {
.
join
(
', '
);
.
join
(
', '
);
}
}
}
}
class
FetchError
extends
Error
{
final
int
statusCode
;
final
String
body
;
FetchError
(
this
.
statusCode
,
this
.
body
);
@override
String
toString
()
=
>
'Server responded with status code
$statusCode
\n
$body
'
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment