Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit 4b396c1

Browse files
committed
chore: add exception and customize error message
1 parent 8365e04 commit 4b396c1

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package be.nicholasmeyers.vwgroupconnector.exception;
22

33
public class LoginException extends RuntimeException {
4-
public LoginException(String message) {
5-
super(message);
4+
public LoginException(String message, String loginUrl) {
5+
super(message + " " + loginUrl);
66
}
77
}

src/main/java/be/nicholasmeyers/vwgroupconnector/resource/StartAuthorization.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
public class StartAuthorization {
44
private final String cookie;
55
private final String relayState;
6+
private final String loginUrl;
67

7-
public StartAuthorization(String cookie, String relayState) {
8+
public StartAuthorization(String cookie, String relayState, String loginUrl) {
89
this.cookie = cookie;
910
this.relayState = relayState;
11+
this.loginUrl = loginUrl;
1012
}
1113

1214
public String getCookie() {
@@ -16,4 +18,8 @@ public String getCookie() {
1618
public String getRelayState() {
1719
return relayState;
1820
}
21+
22+
public String getLoginUrl() {
23+
return loginUrl;
24+
}
1925
}

src/main/java/be/nicholasmeyers/vwgroupconnector/web/out/IdentityClientImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public StartAuthorization getAuthorizationEndpoint(String redirectUri, String cl
6161
String cookie = getCookieHeader(response.headers());
6262
cookie = cookie.substring(0, cookie.indexOf(";"));
6363
String relayState = location.substring(location.indexOf("?relayState") + 12);
64-
return new StartAuthorization(cookie, relayState);
64+
return new StartAuthorization(cookie, relayState, location);
6565
}
6666

6767
@Override
@@ -112,7 +112,7 @@ public FinalAuthorizationInfo getFinalAuthorizationInfo(String client, StartAuth
112112
String responseBody = getResponseBody(response.body());
113113
response.close();
114114
if (response.status() == 303) {
115-
throw new LoginException("Failed to log in (can't get the final authorization info). Please log in manually to a browser to authorize and accept the terms and conditions.");
115+
throw new LoginException("Failed to log in (can't get the final authorization info). Please log in manually to a browser to authorize and accept the terms and conditions.", startAuthorization.getLoginUrl());
116116
}
117117

118118
String hmac = getHmacFromString(responseBody);
@@ -133,6 +133,9 @@ public SsoLogin postEmailPassword(String client, StartAuthorization startAuthori
133133
headers.put("Cookie", startAuthorization.getCookie() + "; " + authorizationInfo.getCookie());
134134
Response response = identityClient.postEmailPassword(resource, headers, client);
135135
response.close();
136+
if (response.status() == 303) {
137+
throw new LoginException("Failed to log in (can't get the final authorization info). Please log in manually to a browser to authorize and accept the terms and conditions.", startAuthorization.getLoginUrl());
138+
}
136139

137140
String location = getLocationHeader(response.headers());
138141
String user = location.substring(location.indexOf("userId") + 7);
@@ -156,7 +159,7 @@ public ConsentInfo ssoLogin(String client, StartAuthorization startAuthorization
156159
Response response = identityClient.ssoLogin(headers, query);
157160
response.close();
158161
if (response.status() == 400) {
159-
throw new LoginException("Failed to log in (can't get the final authorization info). Please log in manually to a browser to authorize and accept the terms and conditions.");
162+
throw new LoginException("Failed to log in (can't get the final authorization info). Please log in manually to a browser to authorize and accept the terms and conditions.", startAuthorization.getLoginUrl());
160163
}
161164

162165
String location = getLocationHeader(response.headers());

0 commit comments

Comments
 (0)