Skip to content

Commit

Permalink
Merge pull request #766 from mjakeman/oscfdezdz/fix-network-handling
Browse files Browse the repository at this point in the history
Fix HTTP responses handling
  • Loading branch information
oscfdezdz authored Jan 31, 2025
2 parents af0c821 + dc79aad commit bfaf7a8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 34 deletions.
7 changes: 1 addition & 6 deletions src/exm-browse-page.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,7 @@ on_first_page_result (GObject *source,

if (error)
{
// Filter 5xx status codes (server errors)
if (error->code / 100 == 5)
gtk_label_set_markup (self->error_label, _("Check <a href='https://status.gnome.org/'>GNOME infrastructure status</a> and try again later"));
else
gtk_label_set_text (self->error_label, _("Check your network status and try again"));

gtk_label_set_text (self->error_label, error->message);
gtk_stack_set_visible_child_name (self->search_stack, "page_error");

g_clear_error (&error);
Expand Down
9 changes: 2 additions & 7 deletions src/exm-comment-dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,15 @@ on_get_comments (GObject *source,
model = exm_comment_provider_get_comments_finish (EXM_COMMENT_PROVIDER (source), res, &error);
self = (ExmCommentDialog *) user_data;

if (error && error->code != 404)
if (error)
{
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{
g_clear_error (&error);
return;
}

// Filter 5xx status codes (server errors)
if (error->code / 100 == 5)
adw_status_page_set_description (self->error_status, _("Check <a href='https://status.gnome.org/'>GNOME infrastructure status</a> and try again later"));
else
adw_status_page_set_description (self->error_status, _("Check your network status and try again"));

adw_status_page_set_description (self->error_status, error->message);
gtk_stack_set_visible_child_name (self->stack, "page_error");

g_clear_error (&error);
Expand Down
18 changes: 9 additions & 9 deletions src/exm-detail-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,17 @@ on_data_loaded (GObject *source,
data = exm_data_provider_get_finish (EXM_DATA_PROVIDER (source), result, &error);
self = EXM_DETAIL_VIEW (user_data);

if (error && error->code != 404)
if (error)
{
// Filter 5xx status codes (server errors)
if (error->code / 100 == 5)
adw_status_page_set_description (self->error_status, _("Check <a href='https://status.gnome.org/'>GNOME infrastructure status</a> and try again later"));
if (error->domain == g_quark_try_string ("request-error-quark") && error->code == 404)
{
gtk_stack_set_visible_child_name (self->stack, "page_empty");
}
else
adw_status_page_set_description (self->error_status, _("Check your network status and try again"));

gtk_stack_set_visible_child_name (self->stack, "page_error");
{
adw_status_page_set_description (self->error_status, error->message);
gtk_stack_set_visible_child_name (self->stack, "page_error");
}

g_clear_error (&error);

Expand Down Expand Up @@ -517,8 +519,6 @@ on_data_loaded (GObject *source,

return;
}

gtk_stack_set_visible_child_name (self->stack, "page_empty");
}

void
Expand Down
10 changes: 3 additions & 7 deletions src/exm-upgrade-assistant.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,10 @@ on_extension_processed (GObject *source,
data = (ExtensionCheckData *) user_data;
self = EXM_UPGRADE_ASSISTANT (data->assistant);

if (error && error->code != 404)
if (error &&
(error->domain != g_quark_try_string ("request-error-quark") || error->code != 404))
{
// Filter 5xx status codes (server errors)
if (error->code / 100 == 5)
adw_status_page_set_description (self->error_status, _("Check <a href='https://status.gnome.org/'>GNOME infrastructure status</a> and try again later"));
else
adw_status_page_set_description (self->error_status, _("Check your network status and try again"));

adw_status_page_set_description (self->error_status, error->message);
gtk_stack_set_visible_child_name (self->stack, "error");

g_clear_error (&error);
Expand Down
2 changes: 1 addition & 1 deletion src/web/exm-image-resolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,6 @@ exm_image_resolver_class_init (ExmImageResolverClass *klass)
static void
exm_image_resolver_init (ExmImageResolver *self)
{
self->session = soup_session_new ();
self->session = soup_session_new_with_options ("timeout", 30, NULL);
g_mutex_init (&self->mutex);
}
13 changes: 9 additions & 4 deletions src/web/exm-request-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "exm-request-handler.h"

#include <gio/gio.h>
#include <glib/gi18n.h>
#include <libsoup/soup.h>

typedef struct
Expand Down Expand Up @@ -89,10 +90,14 @@ request_callback (GObject *source,
{
g_task_return_error (data->task, error);
}
else if (status_code != SOUP_STATUS_OK)
else if (status_code >= SOUP_STATUS_BAD_REQUEST)
{
g_task_return_new_error (data->task, g_quark_from_string ("exm-request-handler"), status_code,
"HTTP error: %d", status_code);
g_task_return_new_error (data->task,
g_quark_from_string ("request-error-quark"),
status_code,
status_code >= SOUP_STATUS_INTERNAL_SERVER_ERROR
? _("Check <a href='https://status.gnome.org/'>GNOME infrastructure status</a> and try again later")
: _("Check your network status and try again"));
}
else
{
Expand Down Expand Up @@ -178,5 +183,5 @@ static void
exm_request_handler_init (ExmRequestHandler *self)
{
ExmRequestHandlerPrivate *priv = exm_request_handler_get_instance_private (self);
priv->session = soup_session_new ();
priv->session = soup_session_new_with_options ("timeout", 30, NULL);
}

0 comments on commit bfaf7a8

Please sign in to comment.