Improved error handling for FollowRemoteService

This commit is contained in:
Eugen Rochko 2016-09-17 17:03:36 +02:00
parent 8c0b19012b
commit 0e9c1a297a
3 changed files with 29 additions and 11 deletions

View file

@ -1,7 +1,8 @@
import { TIMELINE_SET, TIMELINE_UPDATE, TIMELINE_DELETE } from '../actions/timelines'; import { TIMELINE_SET, TIMELINE_UPDATE, TIMELINE_DELETE } from '../actions/timelines';
import { REBLOG_SUCCESS, FAVOURITE_SUCCESS } from '../actions/interactions'; import { REBLOG_SUCCESS, FAVOURITE_SUCCESS } from '../actions/interactions';
import { ACCOUNT_SET_SELF, ACCOUNT_FETCH_SUCCESS } from '../actions/accounts'; import { ACCOUNT_SET_SELF, ACCOUNT_FETCH_SUCCESS, ACCOUNT_FOLLOW_SUCCESS, ACCOUNT_UNFOLLOW_SUCCESS } from '../actions/accounts';
import { STATUS_FETCH_SUCCESS } from '../actions/statuses'; import { STATUS_FETCH_SUCCESS } from '../actions/statuses';
import { FOLLOW_SUBMIT_SUCCESS } from '../actions/follow';
import Immutable from 'immutable'; import Immutable from 'immutable';
const initialState = Immutable.Map({ const initialState = Immutable.Map({
@ -97,6 +98,9 @@ export default function timelines(state = initialState, action) {
map.set('me', action.account.id); map.set('me', action.account.id);
}); });
case ACCOUNT_FETCH_SUCCESS: case ACCOUNT_FETCH_SUCCESS:
case FOLLOW_SUBMIT_SUCCESS:
case ACCOUNT_FOLLOW_SUCCESS:
case ACCOUNT_UNFOLLOW_SUCCESS:
return accountToMaps(state, Immutable.fromJS(action.account)); return accountToMaps(state, Immutable.fromJS(action.account));
case STATUS_FETCH_SUCCESS: case STATUS_FETCH_SUCCESS:
return contextToMaps(state, Immutable.fromJS(action.status), Immutable.fromJS(action.context.ancestors), Immutable.fromJS(action.context.descendants)); return contextToMaps(state, Immutable.fromJS(action.status), Immutable.fromJS(action.context.ancestors), Immutable.fromJS(action.context.descendants));

View file

@ -10,6 +10,14 @@ class ApiController < ApplicationController
render json: { error: 'Record not found' }, status: 404 render json: { error: 'Record not found' }, status: 404
end end
rescue_from Goldfinger::Error do
render json: { error: 'Remote account could not be resolved' }, status: 422
end
rescue_from HTTP::Error do
render json: { error: 'Remote data could not be fetched' }, status: 503
end
protected protected
def current_resource_owner def current_resource_owner

View file

@ -31,9 +31,12 @@ class FollowRemoteAccountService < BaseService
feed = get_feed(account.remote_url) feed = get_feed(account.remote_url)
hubs = feed.xpath('//xmlns:link[@rel="hub"]') hubs = feed.xpath('//xmlns:link[@rel="hub"]')
if hubs.empty? || hubs.first.attribute('href').nil? || feed.at_xpath('/xmlns:feed/xmlns:author/xmlns:uri').nil? if hubs.empty? || hubs.first.attribute('href').nil?
Rails.logger.debug "Cannot find PuSH hub or author for #{uri}" raise Goldfinger::Error, "No PubSubHubbub hubs found"
return nil end
if feed.at_xpath('/xmlns:feed/xmlns:author/xmlns:uri').nil?
raise Goldfinger::Error, "No author URI found"
end end
account.uri = feed.at_xpath('/xmlns:feed/xmlns:author/xmlns:uri').content account.uri = feed.at_xpath('/xmlns:feed/xmlns:author/xmlns:uri').content
@ -53,9 +56,6 @@ class FollowRemoteAccountService < BaseService
end end
return account return account
rescue Goldfinger::Error, HTTP::Error
Rails.logger.debug "Error while fetching data for #{uri}"
nil
end end
private private
@ -89,3 +89,9 @@ class FollowRemoteAccountService < BaseService
HTTP HTTP
end end
end end
class NoAuthorFeedError < StandardError
end
class NoHubError < StandardError
end