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

Commit 69e6288

Browse files
committed
Merge branch 'release/0.1.2'
2 parents 3edc728 + 0f6bd3b commit 69e6288

5 files changed

Lines changed: 119 additions & 5 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>FroxyNetwork</groupId>
66
<artifactId>FroxyNetwork</artifactId>
7-
<version>0.1</version>
7+
<version>0.1.2</version>
88
<packaging>jar</packaging>
99

1010
<name>FroxyNetwork</name>

src/main/java/com/froxynetwork/froxynetwork/App.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public App() throws Exception {
4040
String clientSecret = "SECRET_ecfdc21a8d5022e2db64b1315b087aaf";
4141
NetworkManager nm = new NetworkManager("http://localhost/", clientId, clientSecret);
4242
ServiceManager sm = nm.getNetwork();
43+
4344
// Add server
4445
sm.getServerService().asyncAddServer("koth_1", 20001, new Callback<Server>() {
4546
@Override
@@ -56,8 +57,29 @@ public void onResponse(Server server) {
5657
@Override
5758
public void onResponse(Server response) {
5859
System.out.println(response);
59-
// Shutdown at the end
60-
nm.shutdown();
60+
sm.getServerService().asyncGetServer(999, new Callback<Server>() {
61+
62+
@Override
63+
public void onResponse(Server response2) {
64+
System.out.println(response2);
65+
// Shutdown at the end
66+
nm.shutdown();
67+
};
68+
69+
@Override
70+
public void onFailure(RestException ex) {
71+
ex.printStackTrace();
72+
// Shutdown at the end
73+
nm.shutdown();
74+
}
75+
76+
@Override
77+
public void onFatalFailure(Throwable t) {
78+
t.printStackTrace();
79+
// Shutdown at the end
80+
nm.shutdown();
81+
}
82+
});
6183
};
6284

6385
@Override
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.froxynetwork.froxynetwork.network.output.data;
2+
3+
import com.froxynetwork.froxynetwork.network.output.data.server.ServerDataOutput;
4+
5+
import lombok.Getter;
6+
7+
/**
8+
* MIT License
9+
*
10+
* Copyright (c) 2019 FroxyNetwork
11+
*
12+
* Permission is hereby granted, free of charge, to any person obtaining a copy
13+
* of this software and associated documentation files (the "Software"), to deal
14+
* in the Software without restriction, including without limitation the rights
15+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16+
* copies of the Software, and to permit persons to whom the Software is
17+
* furnished to do so, subject to the following conditions:
18+
*
19+
* The above copyright notice and this permission notice shall be included in
20+
* all copies or substantial portions of the Software.
21+
*
22+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28+
* SOFTWARE.
29+
*
30+
* @author 0ddlyoko
31+
*/
32+
@Getter
33+
public enum Error {
34+
METHOD_NOT_IMPLEMENTED(0, "This method is not implemented"),
35+
GLOBAL_ERROR(1, "Error #{errorCode} : {error}"),
36+
GLOBAL_UNKNOWN(2, "Unknown error"),
37+
GLOBAL_NO_PERMISSION(3, "You don't have the permission to perform this operation"),
38+
GLOBAL_DATA_INVALID(4, "Invalid data value !"),
39+
GLOBAL_CONTROLLER_NOT_FOUND(5, "No controller found for your request !"),
40+
GLOBAL_UNKNOWN_ERROR(6, "An error has occured while performing the operation"),
41+
GLOBAL_TOKEN_INVALUD(7, "Invalid Token, Please save your informations and refresh your page !"),
42+
43+
PLAYER_DATA_LENGTH(100, "The length of the search must be between 1 and 20, or equals to 36."),
44+
PLAYER_NOT_FOUND(101, "Player not found"),
45+
PLAYER_UUID_LENGTH(102, "UUID length must be 36 !"),
46+
PLAYER_UUID_FORMAT(103, "Bad UUID format !"),
47+
PLAYER_PSEUDO_LENGTH(104, "Pseudo length must be between 1 and 20 !"),
48+
PLAYER_IP_LENGTH(105, "Ip length must be between 7 and 15 !"),
49+
PLAYER_IP_FORMAT(106, "Bad ip format !"),
50+
PLAYER_UUID_EXISTS(107, "UUID already exist !"),
51+
PLAYER_PSEUDO_EXISTS(108, "Pseudo already exist !"),
52+
PLAYER_DISPLAYNAME_LENGTH(109, "DisplayName length must be between 1 and 20 !"),
53+
PLAYER_COINS_POSITIVE(110, "Coins must be positive !"),
54+
PLAYER_LEVEL_POSITIVE(111, "Level must be positive !"),
55+
PLAYER_EXP_POSITIVE(112, "Exp must be positive !"),
56+
PLAYER_TIME_FORMAT(113, "Bad time format !"),
57+
PLAYER_LASTLOGIN_GREATER(114, "LastLogin must be greater than saved LastLogin !"),
58+
59+
SERVER_ID_INVALID(200, "Invalid id"),
60+
SERVER_NOT_FOUND(201, "Server not found"),
61+
SERVER_NAME_INVALID(202, "Name must be a string !"),
62+
SERVER_NAME_LENGTH(203, "Name length must be between 1 and 16 !"),
63+
SERVER_PORT_INVALID(204, "Port must be a correct number and between 1 and 65535 !"),
64+
SERVER_SAVING(205, "Error while saving client_id and client_secret"),
65+
SERVER_STATUS_INVALID(206, "Status must be '" + ServerDataOutput.ServerStatus.WAITING + "', '" + ServerDataOutput.ServerStatus.STARTED + "' or '" + ServerDataOutput.ServerStatus.ENDING + "' !"),
66+
SERVER_STATUS_BEFORE(207, "Invalid status, current is {currentStatus} !"),
67+
SERVER_ACTUALLY_ENDED(208, "This server is already ended !");
68+
69+
private int id;
70+
private String message;
71+
72+
private Error(int id, String message) {
73+
this.id = id;
74+
this.message = message;
75+
}
76+
77+
public static Error getFromId(int id) {
78+
for (Error error : values())
79+
if (error.id == id)
80+
return error;
81+
return null;
82+
}
83+
}

src/main/java/com/froxynetwork/froxynetwork/network/output/data/GeneralDataOutput.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@
3434
public class GeneralDataOutput<T> {
3535

3636
private boolean error;
37-
37+
3838
private int code;
3939

40+
@SerializedName("error_id")
41+
private String errorId;
42+
4043
@SerializedName("error_message")
4144
private String errorMessage;
4245

src/main/java/com/froxynetwork/froxynetwork/network/service/ServiceHelper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ protected static <T extends GeneralDataOutput<U>, U> T response(Response<T> resp
8080
body = response.body();
8181
} else {
8282
String json = response.errorBody().string();
83-
body = new Gson().fromJson(json, clazz);
83+
try {
84+
body = new Gson().fromJson(json, clazz);
85+
} catch (Exception ex) {
86+
if (LOG.isErrorEnabled())
87+
LOG.error("Error while parsing result from REST server: {}", json);
88+
throw ex;
89+
}
8490
}
8591
if (LOG.isDebugEnabled())
8692
LOG.debug("Got code {}, body = {}", response.code(), body.toJson());

0 commit comments

Comments
 (0)