Skip to content

Commit e81358f

Browse files
committed
Add exception and error
1 parent 513bef1 commit e81358f

9 files changed

Lines changed: 72 additions & 115 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33

44
# Ignore Gradle build output directory
55
build
6+
7+
# IDEA
8+
.idea/
9+
10+
# macOS
11+
.DS_Store

.idea/gradle.xml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.idea/jarRepositories.xml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.idea/misc.xml

Lines changed: 0 additions & 5 deletions
This file was deleted.

.idea/workspace.xml

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/main/java/org/mushare/pluto/Pluto.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
public class Pluto {
44

55
private PublicKeyManager keyManager;
6+
private String appId;
67

78
private Pluto() {
89
super();
@@ -16,10 +17,27 @@ public void setKeyManager(PublicKeyManager keyManager) {
1617
this.keyManager = keyManager;
1718
}
1819

20+
public String getAppId() {
21+
return appId;
22+
}
23+
24+
public void setAppId(String appId) {
25+
this.appId = appId;
26+
}
27+
1928
private static Pluto shared = new Pluto();
2029

21-
public static void setup(String server) {
30+
public static void setup(String server, String appId) {
2231
shared.setKeyManager(new PublicKeyManager(server));
32+
shared.setAppId(appId);
33+
}
34+
35+
public static void auth(String token) {
36+
37+
}
38+
39+
public static void auth(String token, String scope) {
40+
2341
}
2442

2543
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.mushare.pluto.exception;
2+
3+
public class PlutoError extends Error {
4+
5+
private PlutoErrorCode code;
6+
7+
public PlutoError(PlutoErrorCode code) {
8+
super(code.toString());
9+
this.code = code;
10+
}
11+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.mushare.pluto.exception;
2+
3+
public enum PlutoErrorCode {
4+
expired,
5+
appIdError,
6+
unauthorized,
7+
signatureError;
8+
9+
@Override
10+
public String toString() {
11+
switch (this) {
12+
case expired:
13+
return "JWT token is expired.";
14+
case appIdError:
15+
return "App id is not compatiable.";
16+
case unauthorized:
17+
return "Unauthorized user, make sure the user contains the scopes.";
18+
case signatureError:
19+
return "Cannot verify signature";
20+
default:
21+
return "Unknown pluto error";
22+
}
23+
}
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.mushare.pluto.exception;
2+
3+
public class PlutoException extends RuntimeException {
4+
5+
private final PlutoError error;
6+
7+
public PlutoException(PlutoError error) {
8+
super();
9+
this.error = error;
10+
}
11+
12+
}

0 commit comments

Comments
 (0)