Skip to content

Commit 6a8bf54

Browse files
committed
fix: fix false positive failure when edit post on Android
Seems the cronet client handles redirect for us.
1 parent 71eccc2 commit 6a8bf54

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/features/post/repository/post_edit_repository.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,18 @@ final class PostEditRepository with LoggerMixin {
9090
final resp = respEither.unwrap();
9191
// When post succeed, server responses 301.
9292
// If we got a 200, likely we ran into some error.
93-
if (resp.statusCode == HttpStatus.ok) {
94-
final document = parseHtmlDocument(resp.data as String);
95-
return left(
96-
PostEditFailedToUploadResult(document.querySelector('div#messagetext > p')?.innerText ?? 'unknown error'),
97-
);
93+
//
94+
// When using native http, or say if we are on Android, whe same post requests returns different status code which
95+
// is normally a 200 response. That's weired, but pass it, anyway.
96+
//
97+
// Now we do a more permissive check, reply on message text info more than http status code.
98+
final document = parseHtmlDocument(resp.data as String);
99+
final messageTextNode = document.querySelector('div#messagetext > p');
100+
if (messageTextNode != null) {
101+
return left(PostEditFailedToUploadResult(messageTextNode.innerText));
98102
}
99-
if (resp.statusCode != HttpStatus.movedPermanently) {
103+
104+
if (resp.statusCode != HttpStatus.ok && resp.statusCode != HttpStatus.movedPermanently) {
100105
return left(HttpRequestFailedException(resp.statusCode));
101106
}
102107

0 commit comments

Comments
 (0)