Adding catcher for refresh_spotify_token when not enabled; fixes #565; Starting translation key migration for exceptions

This commit is contained in:
James Barnsley
2020-08-24 21:15:25 +12:00
parent 78f9942c65
commit deb75fc54b
9 changed files with 134 additions and 62 deletions

View File

@ -1020,14 +1020,24 @@ class IrisCore(pykka.ThreadingActor):
async def refresh_spotify_token(self, *args, **kwargs): async def refresh_spotify_token(self, *args, **kwargs):
callback = kwargs.get("callback", None) callback = kwargs.get("callback", None)
# Use client_id and client_secret from config try:
# This was introduced in Mopidy-Spotify 3.1.0 # Use client_id and client_secret from config
url = "https://auth.mopidy.com/spotify/token" # This was introduced in Mopidy-Spotify 3.1.0
data = { url = "https://auth.mopidy.com/spotify/token"
"client_id": self.config["spotify"]["client_id"], data = {
"client_secret": self.config["spotify"]["client_secret"], "client_id": self.config["spotify"]["client_id"],
"grant_type": "client_credentials", "client_secret": self.config["spotify"]["client_secret"],
} "grant_type": "client_credentials",
}
except (Exception) as e:
error = {
"message": "Could not refresh Spotify token: invalid configuration"
}
if callback:
callback(False, error)
else:
return error
try: try:
http_client = tornado.httpclient.AsyncHTTPClient() http_client = tornado.httpclient.AsyncHTTPClient()
@ -1056,7 +1066,7 @@ class IrisCore(pykka.ThreadingActor):
except (urllib.error.HTTPError, urllib.error.URLError) as e: except (urllib.error.HTTPError, urllib.error.URLError) as e:
error = json.loads(e.read()) error = json.loads(e.read())
error = { error = {
"message": "Could not refresh token: " "message": "Could not refresh Spotify token: "
+ error["error_description"] + error["error_description"]
} }
@ -1127,11 +1137,11 @@ class IrisCore(pykka.ThreadingActor):
except (urllib.error.HTTPError, urllib.error.URLError) as e: except (urllib.error.HTTPError, urllib.error.URLError) as e:
error = json.loads(e.read()) error = json.loads(e.read())
error = { error = {
"message": "Could not fetch Spotify recommendations: " "message": "Could not fetch Genius lyrics: "
+ error["error_description"] + error["error_description"]
} }
logger.error( logger.error(
"Could not fetch Spotify recommendations: " "Could not fetch Genius lyrics: "
+ error["error_description"] + error["error_description"]
) )
logger.debug(error) logger.debug(error)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -106,7 +106,7 @@
// Release details // Release details
// These are automatically injected to built HTML // These are automatically injected to built HTML
var build = "1598145259"; var build = "1598260330";
var version = "3.52.2"; var version = "3.52.2";
// Construct the script tag // Construct the script tag

View File

@ -5,7 +5,8 @@ name: English
## ##
errors: errors:
uri_not_found: 'Could not find anything with URI %{uri}' uri_not_found: 'Could not find anything with URI %{uri}'
could_not_load: Could not load could_not_load: 'Could not load %{name}'
could_not_load_library: 'Could not load %{name} from %{provider}'
no_results: No results found no_results: No results found
authorization_required: 'You must authorize %{provider} first' authorization_required: 'You must authorize %{provider} first'
enable_first: 'Enable %{provider} first' enable_first: 'Enable %{provider} first'

View File

@ -17,6 +17,7 @@ import {
formatAlbum, formatAlbum,
} from '../../util/format'; } from '../../util/format';
import URILink from '../../components/URILink'; import URILink from '../../components/URILink';
import { i18n } from '../../locale';
const coreActions = require('../../services/core/actions'); const coreActions = require('../../services/core/actions');
const uiActions = require('../../services/ui/actions'); const uiActions = require('../../services/ui/actions');
@ -1604,10 +1605,13 @@ export function getLibraryTracksAndPlayProcessor(data) {
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_TRACKS_AND_PLAY_PROCESSOR')); dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_TRACKS_AND_PLAY_PROCESSOR'));
} }
}, },
(error) => { () => {
dispatch(coreActions.handleException( dispatch(uiActions.processFinished(
'Could not load library tracks', 'SPOTIFY_GET_LIBRARY_TRACKS_AND_PLAY_PROCESSOR',
error, {
content: 'Could not load library tracks',
level: 'error',
},
)); ));
}, },
); );
@ -1818,11 +1822,11 @@ export function getLibraryPlaylists() {
if (!last_run) { if (!last_run) {
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR', 'Loading Spotify playlists', { next: 'me/playlists?limit=50' })); dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR', 'Loading Spotify playlists', { next: 'me/playlists?limit=50' }));
} else if (last_run.status == 'cancelled') { } else if (last_run.status === 'cancelled') {
dispatch(uiActions.resumeProcess('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR')); dispatch(uiActions.resumeProcess('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR'));
// We've already finished, but the status has been flushed // We've already finished, but the status has been flushed
} else if (last_run.status == 'finished' && !getState().spotify.library_playlists_loaded_all) { } else if (last_run.status === 'finished' && !getState().spotify.library_playlists_loaded_all) {
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR', 'Loading Spotify playlists', { next: 'me/playlists?limit=50' })); dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR', 'Loading Spotify playlists', { next: 'me/playlists?limit=50' }));
} }
}; };
@ -1868,10 +1872,19 @@ export function getLibraryPlaylistsProcessor(data) {
dispatch({ type: 'SPOTIFY_LIBRARY_PLAYLISTS_LOADED_ALL' }); dispatch({ type: 'SPOTIFY_LIBRARY_PLAYLISTS_LOADED_ALL' });
} }
}, },
(error) => { () => {
dispatch(coreActions.handleException( dispatch(uiActions.processFinished(
'Could not load library playlists', 'SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR',
error, {
content: i18n(
'errors.could_not_load_library',
{
name: i18n('library.playlists.title'),
provider: i18n('services.spotify.title'),
},
),
level: 'error',
},
)); ));
}, },
); );
@ -1889,11 +1902,11 @@ export function getLibraryArtists() {
if (!last_run) { if (!last_run) {
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR', 'Loading Spotify artists', { next: 'me/following?type=artist&limit=50' })); dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR', 'Loading Spotify artists', { next: 'me/following?type=artist&limit=50' }));
} else if (last_run.status == 'cancelled') { } else if (last_run.status === 'cancelled') {
dispatch(uiActions.resumeProcess('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR')); dispatch(uiActions.resumeProcess('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR'));
// We've already finished, but the status has been flushed // We've already finished, but the status has been flushed
} else if (last_run.status == 'finished' && !getState().spotify.library_artists_loaded_all) { } else if (last_run.status === 'finished' && !getState().spotify.library_artists_loaded_all) {
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR', 'Loading Spotify artists', { next: 'me/following?type=artist&limit=50' })); dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR', 'Loading Spotify artists', { next: 'me/following?type=artist&limit=50' }));
} }
}; };
@ -1927,10 +1940,19 @@ export function getLibraryArtistsProcessor(data) {
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR')); dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR'));
} }
}, },
(error) => { () => {
dispatch(coreActions.handleException( dispatch(uiActions.processFinished(
'Could not load library artists', 'SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR',
error, {
content: i18n(
'errors.could_not_load_library',
{
name: i18n('library.artists.title'),
provider: i18n('services.spotify.title'),
},
),
level: 'error',
},
)); ));
}, },
); );
@ -1948,11 +1970,11 @@ export function getLibraryAlbums() {
if (!last_run) { if (!last_run) {
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR', 'Loading Spotify albums', { next: 'me/albums?limit=50' })); dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR', 'Loading Spotify albums', { next: 'me/albums?limit=50' }));
} else if (last_run.status == 'cancelled') { } else if (last_run.status === 'cancelled') {
dispatch(uiActions.updateProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR', 'Loading Spotify albums', { next: 'me/albums?limit=50' })); dispatch(uiActions.updateProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR', 'Loading Spotify albums', { next: 'me/albums?limit=50' }));
// We've already finished, but the status has been flushed // We've already finished, but the status has been flushed
} else if (last_run.status == 'finished' && !getState().spotify.library_albums_loaded_all) { } else if (last_run.status === 'finished' && !getState().spotify.library_albums_loaded_all) {
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR', 'Loading Spotify albums', { next: 'me/albums?limit=50' })); dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR', 'Loading Spotify albums', { next: 'me/albums?limit=50' }));
} }
}; };
@ -1997,10 +2019,19 @@ export function getLibraryAlbumsProcessor(data) {
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR')); dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR'));
} }
}, },
(error) => { () => {
dispatch(coreActions.handleException( dispatch(uiActions.processFinished(
'Could not load library albums', 'SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR',
error, {
content: i18n(
'errors.could_not_load_library',
{
name: i18n('library.albums.title'),
provider: i18n('services.spotify.title'),
},
),
level: 'error',
},
)); ));
}, },
); );

View File

@ -21,8 +21,8 @@ const SpotifyMiddleware = (function () {
switch (action.type) { switch (action.type) {
case 'SPOTIFY_AUTHORIZATION_GRANTED': case 'SPOTIFY_AUTHORIZATION_GRANTED':
if (store.getState().ui.allow_reporting) { if (store.getState().ui.allow_reporting) {
ReactGA.event({ category: 'Spotify', action: 'Authorization granted' }); ReactGA.event({ category: 'Spotify', action: 'Authorization granted' });
} }
// Flush out the previous user's library // Flush out the previous user's library
store.dispatch(spotifyActions.flushLibrary()); store.dispatch(spotifyActions.flushLibrary());

View File

@ -61,12 +61,14 @@ class LibraryPlaylists extends React.Component {
getSpotifyLibrary = () => { getSpotifyLibrary = () => {
const { const {
source, source,
spotify_available,
spotify_library_playlists_status, spotify_library_playlists_status,
spotifyActions: { spotifyActions: {
getLibraryPlaylists, getLibraryPlaylists,
}, },
} = this.props; } = this.props;
if (!spotify_available) return;
if (source !== 'spotify' && source !== 'all') return; if (source !== 'spotify' && source !== 'all') return;
if (spotify_library_playlists_status === 'finished') return; if (spotify_library_playlists_status === 'finished') return;
if (spotify_library_playlists_status === 'started') return; if (spotify_library_playlists_status === 'started') return;