Improve chat-view error visuals

This commit is contained in:
Nutcake 2023-05-02 10:22:04 +02:00
parent 8417a29ffe
commit c63692ec31
2 changed files with 31 additions and 7 deletions

View file

@ -88,6 +88,14 @@ class ApiClient {
} }
static void checkResponse(http.Response response) { static void checkResponse(http.Response response) {
if (response.statusCode == 429) {
throw "Sorry, you are being rate limited";
}
if (response.statusCode == 403) {
tryCachedLogin();
// TODO: Show the login screen again if cached login was unsuccessful.
throw "You are not authorized to do that.";
}
if (response.statusCode != 200) { if (response.statusCode != 200) {
throw "Unknown Error${kDebugMode ? ": ${response.statusCode}|${response.body}" : ""}"; throw "Unknown Error${kDebugMode ? ": ${response.statusCode}|${response.body}" : ""}";
} }

View file

@ -92,6 +92,24 @@ class _MessagesState extends State<Messages> {
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.hasData) { if (snapshot.hasData) {
final cache = snapshot.data as MessageCache; final cache = snapshot.data as MessageCache;
if (cache.messages.isEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.message_outlined),
Padding(
padding: const EdgeInsets.symmetric(vertical: 24),
child: Text(
"There are no messages here\nWhy not say hello?",
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleMedium,
),
)
],
),
);
}
return ListView.builder( return ListView.builder(
reverse: true, reverse: true,
itemCount: cache.messages.length, itemCount: cache.messages.length,
@ -115,9 +133,10 @@ class _MessagesState extends State<Messages> {
.of(context) .of(context)
.textTheme .textTheme
.titleMedium,), .titleMedium,),
const SizedBox(height: 16,), Padding(
Text("${snapshot.error}"), padding: const EdgeInsets.all(16),
const Spacer(), child: Text("${snapshot.error}"),
),
TextButton.icon( TextButton.icon(
onPressed: () { onPressed: () {
setState(() { setState(() {
@ -125,10 +144,7 @@ class _MessagesState extends State<Messages> {
}); });
}, },
style: TextButton.styleFrom( style: TextButton.styleFrom(
backgroundColor: Theme
.of(context)
.colorScheme
.secondaryContainer,
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: 16, horizontal: 16), vertical: 16, horizontal: 16),
), ),