Merge pull request #126 from ultrasonic/better-error-handling
Better error handling
This commit is contained in:
commit
86fcbb5650
|
@ -12,7 +12,7 @@ sourceSets {
|
|||
dependencies {
|
||||
api other.kotlinStdlib
|
||||
api other.retrofit
|
||||
implementation other.jacksonConverter
|
||||
api other.jacksonConverter
|
||||
implementation(other.jacksonKotlin) {
|
||||
exclude module: 'kotlin-reflect'
|
||||
}
|
||||
|
|
|
@ -698,7 +698,7 @@ public class RESTMusicService implements MusicService {
|
|||
throws SubsonicRESTException, IOException {
|
||||
if (response.hasError() || response.getStream() == null) {
|
||||
if (response.getApiError() != null) {
|
||||
throw new SubsonicRESTException(response.getApiError().getCode(), "rest error");
|
||||
throw new SubsonicRESTException(response.getApiError());
|
||||
} else {
|
||||
throw new IOException("Failed to make endpoint request, code: " +
|
||||
response.getResponseHttpCode());
|
||||
|
|
|
@ -1,26 +1,27 @@
|
|||
package org.moire.ultrasonic.service.parser;
|
||||
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError;
|
||||
|
||||
/**
|
||||
* Exception returned by API with given {@code code}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SubsonicRESTException extends Exception
|
||||
{
|
||||
public class SubsonicRESTException extends Exception {
|
||||
private final SubsonicError error;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 859440717343258203L;
|
||||
private final int code;
|
||||
public SubsonicRESTException(final SubsonicError error) {
|
||||
super("Api error: " + error.name());
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public SubsonicRESTException(int code, String message)
|
||||
{
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
public int getCode()
|
||||
{
|
||||
return error.getCode();
|
||||
}
|
||||
|
||||
public int getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
public SubsonicError getError() {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,11 @@ import android.app.Activity;
|
|||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import org.moire.ultrasonic.R;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.moire.ultrasonic.R;
|
||||
import org.moire.ultrasonic.service.parser.SubsonicRESTException;
|
||||
import org.moire.ultrasonic.subsonic.RestErrorMapper;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
@ -80,15 +82,18 @@ public abstract class BackgroundTask<T> implements ProgressListener
|
|||
return activity.getResources().getString(R.string.background_task_not_found);
|
||||
}
|
||||
|
||||
if (error instanceof IOException)
|
||||
if (error instanceof JsonParseException) {
|
||||
return activity.getResources().getString(R.string.background_task_parse_error);
|
||||
}
|
||||
|
||||
if (error instanceof IOException)
|
||||
{
|
||||
return activity.getResources().getString(R.string.background_task_network_error);
|
||||
}
|
||||
|
||||
if (error instanceof XmlPullParserException)
|
||||
{
|
||||
return activity.getResources().getString(R.string.background_task_parse_error);
|
||||
}
|
||||
if (error instanceof SubsonicRESTException) {
|
||||
return RestErrorMapper.getLocalizedErrorMessage((SubsonicRESTException) error, activity);
|
||||
}
|
||||
|
||||
String message = error.getMessage();
|
||||
if (message != null)
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
@file:JvmName("RestErrorMapper")
|
||||
package org.moire.ultrasonic.subsonic
|
||||
|
||||
import android.content.Context
|
||||
import org.moire.ultrasonic.R
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.GENERIC
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.INCOMPATIBLE_CLIENT_PROTOCOL_VERSION
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.INCOMPATIBLE_SERVER_PROTOCOL_VERSION
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.REQUESTED_DATA_WAS_NOT_FOUND
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.REQUIRED_PARAM_MISSING
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.TOKEN_AUTH_NOT_SUPPORTED_FOR_LDAP
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.TRIAL_PERIOD_IS_OVER
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.USER_NOT_AUTHORIZED_FOR_OPERATION
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.WRONG_USERNAME_OR_PASSWORD
|
||||
import org.moire.ultrasonic.service.parser.SubsonicRESTException
|
||||
|
||||
/**
|
||||
* Extension for [SubsonicRESTException] that returns localized error string, that can used to
|
||||
* display error reason for user.
|
||||
*/
|
||||
fun SubsonicRESTException.getLocalizedErrorMessage(context: Context): String =
|
||||
when (error) {
|
||||
GENERIC -> context.getString(R.string.api_subsonic_generic)
|
||||
REQUIRED_PARAM_MISSING -> context.getString(R.string.api_subsonic_param_missing)
|
||||
INCOMPATIBLE_CLIENT_PROTOCOL_VERSION -> context
|
||||
.getString(R.string.api_subsonic_upgrade_client)
|
||||
INCOMPATIBLE_SERVER_PROTOCOL_VERSION -> context
|
||||
.getString(R.string.api_subsonic_upgrade_server)
|
||||
WRONG_USERNAME_OR_PASSWORD -> context.getString(R.string.api_subsonic_not_authenticated)
|
||||
TOKEN_AUTH_NOT_SUPPORTED_FOR_LDAP -> context
|
||||
.getString(R.string.api_subsonic_token_auth_not_supported_for_ldap)
|
||||
USER_NOT_AUTHORIZED_FOR_OPERATION -> context
|
||||
.getString(R.string.api_subsonic_not_authorized)
|
||||
TRIAL_PERIOD_IS_OVER -> context.getString(R.string.api_subsonic_trial_period_is_over)
|
||||
REQUESTED_DATA_WAS_NOT_FOUND -> context
|
||||
.getString(R.string.api_subsonic_requested_data_was_not_found)
|
||||
else -> context.getString(R.string.api_subsonic_unknown_api_error)
|
||||
}
|
|
@ -108,12 +108,8 @@
|
|||
<string name="music_library.label_offline">Medios sin conexión</string>
|
||||
<string name="music_service.retry">Se ha producido un error de red. Reintento %1$d de %2$d.</string>
|
||||
<string name="parser.artist_count">Obtenido(s) %d artista(s).</string>
|
||||
<string name="parser.not_authenticated">Nombre de usuario o contraseña incorrectos.</string>
|
||||
<string name="parser.not_authorized">No autorizado. Comprueba los permisos de usuario en el servidor de Subsonic.</string>
|
||||
<string name="parser.reading">Leyendo del servidor.</string>
|
||||
<string name="parser.reading_done">Leyendo del servidor. ¡Hecho!</string>
|
||||
<string name="parser.upgrade_client">Versiones incompatibles. Por favor actualiza la aplicación de Android UltraSonic.</string>
|
||||
<string name="parser.upgrade_server">Versiones incompatibles. Por favor actualiza el servidor de Subsonic.</string>
|
||||
<string name="playlist.label">Listas de reproducción</string>
|
||||
<string name="playlist.update_info">Actualizar Información</string>
|
||||
<string name="playlist.updated_info">Actualizada la información de la lista de reproducción para %s</string>
|
||||
|
@ -426,4 +422,16 @@
|
|||
<string name="podcasts.label">Podcast</string>
|
||||
<string name="podcasts_channels.empty">No hay canales de Podcasts registrados</string>
|
||||
|
||||
<!-- Subsonic api errors -->
|
||||
<string name="api.subsonic.generic">Error genérico de api.</string>
|
||||
<string name="api.subsonic.token_auth_not_supported_for_ldap">La autenticación por token no es compatible con usuarios LDAP.</string>
|
||||
<string name="api.subsonic.not_authenticated">Nombre de usuario o contraseña incorrectos.</string>
|
||||
<string name="api.subsonic.not_authorized">No autorizado. Comprueba los permisos de usuario en el servidor de Subsonic.</string>
|
||||
<string name="api.subsonic.param_missing">Falta el parámetro requerido.</string>
|
||||
<string name="api.subsonic.requested_data_was_not_found">No se encontraron los datos solicitados.</string>
|
||||
<string name="api.subsonic.trial_period_is_over">El período de prueba ha terminado.</string>
|
||||
<string name="api.subsonic.unknown_api_error">Error de api desconocido.</string>
|
||||
<string name="api.subsonic.upgrade_client">Versiones incompatibles. Por favor actualiza la aplicación de Android UltraSonic.</string>
|
||||
<string name="api.subsonic.upgrade_server">Versiones incompatibles. Por favor actualiza el servidor de Subsonic.</string>
|
||||
|
||||
</resources>
|
|
@ -108,12 +108,8 @@
|
|||
<string name="music_library.label_offline">Musique hors-ligne</string>
|
||||
<string name="music_service.retry">Une erreur de réseau s\'est produite. Essai %1$d de %2$d.</string>
|
||||
<string name="parser.artist_count">%d artistes récupérés.</string>
|
||||
<string name="parser.not_authenticated">Mauvais nom d\'usager ou mot de passe.</string>
|
||||
<string name="parser.not_authorized">Non autorisé. Vérifiez les permissions de l\'utilisateur dans le serveur Subsonic.</string>
|
||||
<string name="parser.reading">Lecture du serveur.</string>
|
||||
<string name="parser.reading_done">Lecture du serveur. Terminé!</string>
|
||||
<string name="parser.upgrade_client">Versions incompatible. Veuillez mette à jour l\'application Android UltraSonic.</string>
|
||||
<string name="parser.upgrade_server">Versions incompatible. Veuillez mette à jour le serveur Subsonic.</string>
|
||||
<string name="playlist.label">Playlists</string>
|
||||
<string name="playlist.update_info">Mise à jour des informations</string>
|
||||
<string name="playlist.updated_info">Informations de la playlist %s mises à jour</string>
|
||||
|
@ -426,4 +422,16 @@
|
|||
<string name="podcasts.label">Podcast</string>
|
||||
<string name="podcasts_channels.empty">No podcasts channels registered</string>
|
||||
|
||||
<!-- Subsonic api errors -->
|
||||
<string name="api.subsonic.generic">Erreur api générique.</string>
|
||||
<string name="api.subsonic.token_auth_not_supported_for_ldap">L\'authentification par jeton n\'est pas prise en charge pour les utilisateurs LDAP.</string>
|
||||
<string name="api.subsonic.not_authenticated">Mauvais nom d\'usager ou mot de passe.</string>
|
||||
<string name="api.subsonic.not_authorized">Non autorisé. Vérifiez les permissions de l\'utilisateur dans le serveur Subsonic.</string>
|
||||
<string name="api.subsonic.param_missing">Param nécessaire manquant.</string>
|
||||
<string name="api.subsonic.requested_data_was_not_found">Les données demandées n\'ont pas été trouvées.</string>
|
||||
<string name="api.subsonic.trial_period_is_over">La période d\'essai est terminée.</string>
|
||||
<string name="api.subsonic.unknown_api_error">Erreur d\'api inconnue.</string>
|
||||
<string name="api.subsonic.upgrade_client">Versions incompatible. Veuillez mette à jour l\'application Android UltraSonic.</string>
|
||||
<string name="api.subsonic.upgrade_server">Versions incompatible. Veuillez mette à jour le serveur Subsonic.</string>
|
||||
|
||||
</resources>
|
|
@ -108,12 +108,8 @@
|
|||
<string name="music_library.label_offline">Kapcsolat nélküli médiák</string>
|
||||
<string name="music_service.retry">Hálózati hiba történt! Újrapróbálkozás %1$d - %2$d.</string>
|
||||
<string name="parser.artist_count">%d előadó található a médiakönyvtárban.</string>
|
||||
<string name="parser.not_authenticated">Hibás felhasználónév vagy jelszó!</string>
|
||||
<string name="parser.not_authorized">Nem engedélyezett! Ellenőrizze a felhasználó jogosultságait a Subsonic kiszolgálón!</string>
|
||||
<string name="parser.reading">Olvasás a kiszolgálóról…</string>
|
||||
<string name="parser.reading_done">Olvasás a kiszolgálóról… Kész!</string>
|
||||
<string name="parser.upgrade_client">Nem kompatibilis verzió. Kérjük, frissítse az UltraSonic Android alkalmazást!</string>
|
||||
<string name="parser.upgrade_server">Nem kompatibilis verzió. Kérjük, frissítse a Subsonic kiszolgálót!</string>
|
||||
<string name="playlist.label">Lejátszási listák</string>
|
||||
<string name="playlist.update_info">Módosítás</string>
|
||||
<string name="playlist.updated_info">Módosított lejátszási lista %s</string>
|
||||
|
@ -426,4 +422,16 @@
|
|||
<string name="podcasts.label">Podcast</string>
|
||||
<string name="podcasts_channels.empty">No podcasts channels registered</string>
|
||||
|
||||
<!-- Subsonic api errors -->
|
||||
<string name="api.subsonic.generic">Általános api hiba.</string>
|
||||
<string name="api.subsonic.token_auth_not_supported_for_ldap">Az LDAP-felhasználók számára nem támogatott a token-hitelesítés.</string>
|
||||
<string name="api.subsonic.not_authenticated">Hibás felhasználónév vagy jelszó!</string>
|
||||
<string name="api.subsonic.not_authorized">Nem engedélyezett! Ellenőrizze a felhasználó jogosultságait a Subsonic kiszolgálón!</string>
|
||||
<string name="api.subsonic.param_missing">A szükséges param hiányzik.</string>
|
||||
<string name="api.subsonic.requested_data_was_not_found">A keresett adatokat nem találtuk.</string>
|
||||
<string name="api.subsonic.trial_period_is_over">A próbaidő vége.</string>
|
||||
<string name="api.subsonic.unknown_api_error">Ismeretlen api hiba.</string>
|
||||
<string name="api.subsonic.upgrade_client">Nem kompatibilis verzió. Kérjük, frissítse az UltraSonic Android alkalmazást!</string>
|
||||
<string name="api.subsonic.upgrade_server">Nem kompatibilis verzió. Kérjük, frissítse a Subsonic kiszolgálót!</string>
|
||||
|
||||
</resources>
|
|
@ -111,12 +111,8 @@
|
|||
<string name="music_library.label_offline">Mídia Offline</string>
|
||||
<string name="music_service.retry">Ocorreu um erro de rede. Tentativa %1$d de %2$d.</string>
|
||||
<string name="parser.artist_count">Obtive %d Artistas.</string>
|
||||
<string name="parser.not_authenticated">Login ou senha errada.</string>
|
||||
<string name="parser.not_authorized">Não autorizado. Verifique as permissões do usuário no servidor Subsonic.</string>
|
||||
<string name="parser.reading">Lendo do servidor.</string>
|
||||
<string name="parser.reading_done">Lendo do servidor. Pronto!</string>
|
||||
<string name="parser.upgrade_client">Versões incompativeis. Atualize o aplicativo UltraSonic para Android.</string>
|
||||
<string name="parser.upgrade_server">Versões incompativeis. Atualize o servidor UltraSonic.</string>
|
||||
<string name="playlist.label">Playlists</string>
|
||||
<string name="playlist.update_info">Atualizar Informação</string>
|
||||
<string name="playlist.updated_info">Informação da playlist atualizada para %s</string>
|
||||
|
@ -426,4 +422,16 @@
|
|||
<item quantity="other">Restam %d dias para o fim do período de teste</item>
|
||||
</plurals>
|
||||
|
||||
<!-- Subsonic api errors -->
|
||||
<string name="api.subsonic.generic">Erro de api genérico.</string>
|
||||
<string name="api.subsonic.token_auth_not_supported_for_ldap">A autenticação por token não é suportada para usuários LDAP.</string>
|
||||
<string name="api.subsonic.not_authenticated">Login ou senha errada.</string>
|
||||
<string name="api.subsonic.not_authorized">Não autorizado. Verifique as permissões do usuário no servidor Subsonic.</string>
|
||||
<string name="api.subsonic.param_missing">O parâmetro requerido está faltando.</string>
|
||||
<string name="api.subsonic.requested_data_was_not_found">Os dados solicitados não foram encontrados.</string>
|
||||
<string name="api.subsonic.trial_period_is_over">O período de avaliação acabou.</string>
|
||||
<string name="api.subsonic.unknown_api_error">Erro de api desconhecido.</string>
|
||||
<string name="api.subsonic.upgrade_client">Versões incompativeis. Atualize o aplicativo UltraSonic para Android.</string>
|
||||
<string name="api.subsonic.upgrade_server">Versões incompativeis. Atualize o servidor UltraSonic.</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -111,12 +111,8 @@
|
|||
<string name="music_library.label_offline">Mídia Offline</string>
|
||||
<string name="music_service.retry">Ocorreu um erro de rede. Tentativa %1$d de %2$d.</string>
|
||||
<string name="parser.artist_count">Obtive %d Artistas.</string>
|
||||
<string name="parser.not_authenticated">Login ou senha errada.</string>
|
||||
<string name="parser.not_authorized">Não autorizado. Verifique as permissões do usuário no servidor Subsonic.</string>
|
||||
<string name="parser.reading">Lendo do servidor.</string>
|
||||
<string name="parser.reading_done">Lendo do servidor. Pronto!</string>
|
||||
<string name="parser.upgrade_client">Versões incompativeis. Atualize o aplicativo UltraSonic para Android.</string>
|
||||
<string name="parser.upgrade_server">Versões incompativeis. Atualize o servidor UltraSonic.</string>
|
||||
<string name="playlist.label">Playlists</string>
|
||||
<string name="playlist.update_info">Atualizar Informação</string>
|
||||
<string name="playlist.updated_info">Informação da playlist atualizada para %s</string>
|
||||
|
@ -426,4 +422,16 @@
|
|||
<item quantity="other">Restam %d dias para o fim do período de teste</item>
|
||||
</plurals>
|
||||
|
||||
<!-- Subsonic api errors -->
|
||||
<string name="api.subsonic.generic">Erro de api genérico.</string>
|
||||
<string name="api.subsonic.token_auth_not_supported_for_ldap">A autenticação por token não é suportada para usuários LDAP.</string>
|
||||
<string name="api.subsonic.not_authenticated">Login ou senha errada.</string>
|
||||
<string name="api.subsonic.not_authorized">Não autorizado. Verifique as permissões do usuário no servidor Subsonic.</string>
|
||||
<string name="api.subsonic.param_missing">O parâmetro requerido está faltando.</string>
|
||||
<string name="api.subsonic.requested_data_was_not_found">Os dados solicitados não foram encontrados.</string>
|
||||
<string name="api.subsonic.trial_period_is_over">O período de avaliação acabou.</string>
|
||||
<string name="api.subsonic.unknown_api_error">Erro de api desconhecido.</string>
|
||||
<string name="api.subsonic.upgrade_client">Versões incompativeis. Atualize o aplicativo UltraSonic para Android.</string>
|
||||
<string name="api.subsonic.upgrade_server">Versões incompativeis. Atualize o servidor UltraSonic.</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -111,12 +111,8 @@
|
|||
<string name="music_library.label_offline">Offline Media</string>
|
||||
<string name="music_service.retry">A network error occurred. Retrying %1$d of %2$d.</string>
|
||||
<string name="parser.artist_count">Got %d Artists.</string>
|
||||
<string name="parser.not_authenticated">Wrong username or password.</string>
|
||||
<string name="parser.not_authorized">Not authorized. Check user permissions in Subsonic server.</string>
|
||||
<string name="parser.reading">Reading from server.</string>
|
||||
<string name="parser.reading_done">Reading from server. Done!</string>
|
||||
<string name="parser.upgrade_client">Incompatible versions. Please upgrade UltraSonic Android app.</string>
|
||||
<string name="parser.upgrade_server">Incompatible versions. Please upgrade Subsonic server.</string>
|
||||
<string name="playlist.label">Playlists</string>
|
||||
<string name="playlist.update_info">Update Information</string>
|
||||
<string name="playlist.updated_info">Updated playlist information for %s</string>
|
||||
|
@ -428,4 +424,16 @@
|
|||
<item quantity="other">%d days left of trial period</item>
|
||||
</plurals>
|
||||
|
||||
<!-- Subsonic api errors -->
|
||||
<string name="api.subsonic.generic">Generic api error.</string>
|
||||
<string name="api.subsonic.token_auth_not_supported_for_ldap">Authentication by token is not supported for LDAP users.</string>
|
||||
<string name="api.subsonic.not_authenticated">Wrong username or password.</string>
|
||||
<string name="api.subsonic.not_authorized">Not authorized. Check user permissions in Subsonic server.</string>
|
||||
<string name="api.subsonic.param_missing">Required param is missing.</string>
|
||||
<string name="api.subsonic.requested_data_was_not_found">Requested data was not found.</string>
|
||||
<string name="api.subsonic.trial_period_is_over">Trial period is over.</string>
|
||||
<string name="api.subsonic.unknown_api_error">Unknown api error.</string>
|
||||
<string name="api.subsonic.upgrade_client">Incompatible versions. Please upgrade UltraSonic Android app.</string>
|
||||
<string name="api.subsonic.upgrade_server">Incompatible versions. Please upgrade Subsonic server.</string>
|
||||
|
||||
</resources>
|
Loading…
Reference in New Issue