mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-15 06:49:56 +00:00
show an "user is unauthorized" dialog, if server responds with 401.
This commit is contained in:
1 parent
57330bbf16
commit
1795eaaaab
7 files changed
+43
-17
No files matched your search
@@ -59,4 +59,10 @@
|
||||
<string name="eula">EULA</string>
|
||||
<string name="licence_information">Licence Information</string>
|
||||
|
||||
<!-- HTTP Requests -->
|
||||
<string name="http_request_exception" translatable="false">(Request %1$d) %2$s\nHTTP response code: %3$d.\nHTTP response body: %4$s.</string>
|
||||
<string name="http_request_executed" translatable="false">(Request %d) HTTP request executed.</string>
|
||||
<string name="http_request_aborted" translatable="false">(Request %d) HTTP request aborted.</string>
|
||||
<string name="http_request_failed" translatable="false">(Request %d) HTTP request failed.</string>
|
||||
|
||||
</resources>
|
||||
+9
-8
@@ -94,26 +94,27 @@ public abstract class HttpRequest {
|
||||
try {
|
||||
responseInputStream = doRequest(connection);
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
if (HttpURLConnection.HTTP_UNAUTHORIZED == connection.getResponseCode()) {
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
// 404 errors...
|
||||
throw new FileNotFoundException(String.format(
|
||||
"(Request %d) %s\nHTTP response code: %d.\nHTTP response body: %s.", this.hashCode(),
|
||||
fnfe.getMessage(), connection.getResponseCode(), connection.getResponseMessage()));
|
||||
throw new FileNotFoundException(context.getString(R.string.http_request_exception, this.hashCode(), fnfe.getMessage(), connection.getResponseCode(), connection.getResponseMessage()));
|
||||
}
|
||||
|
||||
validateHttpResponseCode(connection);
|
||||
|
||||
InputStream copiedResponseInputStream = readAndCopyResponse(connection, responseInputStream);
|
||||
|
||||
|
||||
if (copiedResponseInputStream != null) {
|
||||
ExLog.i(context, TAG, String.format("(Request %d) HTTP request executed.", this.hashCode()));
|
||||
ExLog.i(context, TAG, context.getString(R.string.http_request_executed, this.hashCode()));
|
||||
} else {
|
||||
ExLog.i(context, TAG, String.format("(Request %d) HTTP request aborted.", this.hashCode()));
|
||||
ExLog.i(context, TAG, context.getString(R.string.http_request_aborted, this.hashCode()));
|
||||
}
|
||||
|
||||
|
||||
connection.disconnect();
|
||||
return copiedResponseInputStream;
|
||||
} catch (IOException e) {
|
||||
ExLog.i(context, TAG, String.format("(Request %d) HTTP request failed.", this.hashCode()));
|
||||
ExLog.i(context, TAG, context.getString(R.string.http_request_failed, this.hashCode()));
|
||||
throw e;
|
||||
} finally {
|
||||
safeClose(responseInputStream);
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.sap.sailing.android.shared.data.http;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Used for HTTP-Request ResponseCode 401
|
||||
*/
|
||||
public class UnauthorizedException extends IOException {
|
||||
|
||||
}
|
||||
@@ -465,5 +465,6 @@
|
||||
<string name="wind_select_race">Select Race</string>
|
||||
<string name="get_started">Getting Started</string>
|
||||
<string name="get_started_url">http://www.sapsailing.com/gwt/Home.html?locale=de#SolutionsPlace:navigationTab=RaceCommitteeApp</string>
|
||||
<string name="user_unauthorized">Request fehlgeschlagen. User ist nicht autorisiert.</string>
|
||||
|
||||
</resources>
|
||||
@@ -492,5 +492,6 @@
|
||||
<string name="wind_select_race">Select Race</string>
|
||||
<string name="get_started">Getting Started</string>
|
||||
<string name="get_started_url">http://www.sapsailing.com/gwt/Home.html?locale=en#SolutionsPlace:navigationTab=RaceCommitteeApp</string>
|
||||
<string name="user_unauthorized">Request failed. User is unauthorized.</string>
|
||||
|
||||
</resources>
|
||||
+2
-5
@@ -31,10 +31,7 @@ public class LoadFailedDialog extends FragmentAttachedDialogFragment {
|
||||
@Override
|
||||
protected AlertDialog.Builder createDialog(AlertDialog.Builder builder) {
|
||||
return builder
|
||||
.setMessage(String.format(
|
||||
getString(R.string.generic_load_failure),
|
||||
getArguments().getString(ARGS_ERROR_MSG)))
|
||||
.setTitle(getString(R.string.loading_failure))
|
||||
.setIcon(R.drawable.ic_warning_grey_600_36dp);
|
||||
.setMessage(getString(R.string.generic_load_failure, getArguments().getString(ARGS_ERROR_MSG)))
|
||||
.setTitle(getString(R.string.loading_failure));
|
||||
}
|
||||
}
|
||||
+14
-4
@@ -11,12 +11,14 @@ import android.app.Activity;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.LoaderManager.LoaderCallbacks;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.sap.sailing.android.shared.data.http.UnauthorizedException;
|
||||
import com.sap.sailing.domain.base.EventBase;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.data.OnlineDataManager;
|
||||
@@ -101,11 +103,19 @@ public abstract class NamedListFragment<T extends Named> extends LoggableListFra
|
||||
|
||||
showProgressBar(false);
|
||||
|
||||
String message = reason.getMessage();
|
||||
if (message == null) {
|
||||
message = reason.toString();
|
||||
if (reason instanceof UnauthorizedException) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppTheme_AlertDialog);
|
||||
builder.setTitle(R.string.loading_failure);
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
builder.setMessage(getActivity().getString(R.string.user_unauthorized));
|
||||
builder.show();
|
||||
} else {
|
||||
String message = reason.getMessage();
|
||||
if (message == null) {
|
||||
message = reason.toString();
|
||||
}
|
||||
showLoadFailedDialog(message);
|
||||
}
|
||||
showLoadFailedDialog(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user