From b0294c54005288293d6eff69110aeab03d74a7b4 Mon Sep 17 00:00:00 2001 From: "@mykdavies" Date: Fri, 21 Jul 2023 17:09:01 +0200 Subject: [PATCH 1/3] Catch upload errors --- lib/src/pictrs.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/src/pictrs.dart b/lib/src/pictrs.dart index 09165ef..20e5928 100644 --- a/lib/src/pictrs.dart +++ b/lib/src/pictrs.dart @@ -24,6 +24,14 @@ class PictrsApi { req.headers['Cookie'] = 'jwt=$auth'; final res = await req.send(); + if (res.statusCode != 200) { + switch (res.statusCode) { + case 413: + throw const LemmyApiException('pictrs_payload_too_large'); + default: + throw const LemmyApiException('pictrs_unknown_error'); + } + } final Map body = jsonDecode(utf8.decode(await res.stream.toBytes())); body['instance_host'] = host; From b54116cb576df20506468a0a813a2c5b6f12cb4f Mon Sep 17 00:00:00 2001 From: "@mykdavies" Date: Fri, 21 Jul 2023 17:29:40 +0200 Subject: [PATCH 2/3] Use term, not number --- lib/src/pictrs.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/pictrs.dart b/lib/src/pictrs.dart index 20e5928..259cfa3 100644 --- a/lib/src/pictrs.dart +++ b/lib/src/pictrs.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:html'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:http/http.dart' as http; @@ -24,7 +25,7 @@ class PictrsApi { req.headers['Cookie'] = 'jwt=$auth'; final res = await req.send(); - if (res.statusCode != 200) { + if (res.statusCode != HttpStatus.created) { switch (res.statusCode) { case 413: throw const LemmyApiException('pictrs_payload_too_large'); From fdf03e7b8fb9d6b04f36527fbe45d2a2a535616f Mon Sep 17 00:00:00 2001 From: "@mykdavies" Date: Fri, 21 Jul 2023 17:38:33 +0200 Subject: [PATCH 3/3] Revert to codes to avoid adding deps. --- lib/src/pictrs.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/src/pictrs.dart b/lib/src/pictrs.dart index 259cfa3..12b21e8 100644 --- a/lib/src/pictrs.dart +++ b/lib/src/pictrs.dart @@ -1,5 +1,4 @@ import 'dart:convert'; -import 'dart:html'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:http/http.dart' as http; @@ -25,7 +24,7 @@ class PictrsApi { req.headers['Cookie'] = 'jwt=$auth'; final res = await req.send(); - if (res.statusCode != HttpStatus.created) { + if (res.statusCode != 201) { switch (res.statusCode) { case 413: throw const LemmyApiException('pictrs_payload_too_large');