Skip to content

Commit

Permalink
fix errors locale logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauricio Murga committed Mar 17, 2015
1 parent 8f3fe76 commit dbf7fe0
Show file tree
Hide file tree
Showing 20 changed files with 36 additions and 27 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
* Fix getRequest JSONArray to query logic.
=== 1.0.8 2015-11-03
* Make lib compatible with android and add message_to_purchaser.
=== 1.0.9 2015-11-03
* Fix Error locale logic.
2 changes: 1 addition & 1 deletion build/built-jar.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Wed, 11 Mar 2015 18:24:07 -0600
#Tue, 17 Mar 2015 16:24:57 -0600


/Users/mauriciomurga/rails_projects/conekta-java=
Binary file modified build/classes/com/conekta/ApiError.class
Binary file not shown.
Binary file modified build/classes/com/conekta/AuthenticationError.class
Binary file not shown.
Binary file modified build/classes/com/conekta/Conekta.class
Binary file not shown.
Binary file modified build/classes/com/conekta/Error.class
Binary file not shown.
Binary file modified build/classes/com/conekta/MalformedRequestError.class
Binary file not shown.
Binary file modified build/classes/com/conekta/NoConnectionError.class
Binary file not shown.
Binary file modified build/classes/com/conekta/ParameterValidationError.class
Binary file not shown.
Binary file modified build/classes/com/conekta/ProcessingError.class
Binary file not shown.
Binary file modified build/classes/com/conekta/Requestor.class
Binary file not shown.
Binary file modified build/classes/com/conekta/ResourceNotFoundError.class
Binary file not shown.
Binary file modified dist/.DS_Store
Binary file not shown.
Binary file modified dist/ConektaJava.jar
Binary file not shown.
7 changes: 5 additions & 2 deletions nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/mauricio/NetBeansProjects/ConektaJava/test/com/conekta/ChargeTest.java</file>
<file>file:/home/mauricio/NetBeansProjects/ConektaJava/src/com/conekta/Requestor.java</file>
<file>file:/Users/mauriciomurga/rails_projects/conekta-java/src/com/conekta/Requestor.java</file>
<file>file:/Users/mauriciomurga/rails_projects/conekta-java/src/com/conekta/Error.java</file>
<file>file:/Users/mauriciomurga/rails_projects/conekta-java/src/com/conekta/Card.java</file>
<file>file:/Users/mauriciomurga/rails_projects/conekta-java/src/com/conekta/Conekta.java</file>
<file>file:/Users/mauriciomurga/rails_projects/conekta-java/test/com/conekta/ErrorTest.java</file>
</group>
</open-files>
</project-private>
2 changes: 1 addition & 1 deletion src/com/conekta/Conekta.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class Conekta {
public static String apiKey;
public static String apiBase = "https://api.conekta.io";
public static String apiVersion = "1.0.0";
public static final String VERSION = "1.0.8";
public static final String VERSION = "1.0.9";

public static void setApiKey(String apiKey) {
Conekta.apiKey = apiKey;
Expand Down
9 changes: 4 additions & 5 deletions src/com/conekta/Error.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* and open the template in the editor.
*/

import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONException;
import org.json.JSONObject;

Expand All @@ -17,15 +15,16 @@
*/
public class Error extends Exception {

public String message;
public String message_to_purchaser = "Hubo un error al enviar los datos al sistema de pagos.";
public String message = "There was an exception in the library";
public String message_to_purchaser = "Hubo un error al enviar los datos al sistema de pagos.";;
public String type;
public Integer code;
public String params;

public Error(String message, String message_to_purchaser, String type, Integer code, String params) {
super(message);
this.message = message;
if (message != null)
this.message = message;
if (message_to_purchaser != null)
this.message_to_purchaser = message_to_purchaser;
this.type = type;
Expand Down
31 changes: 14 additions & 17 deletions src/com/conekta/Requestor.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void setHeaders() throws Error {
this.connection.setRequestProperty("Accept", "application/vnd.conekta-v"+ Conekta.apiVersion +"+json");
this.connection.setRequestProperty("Content-Type", " application/x-www-form-urlencoded");
} catch (Exception e) {
throw new Error(e.toString(), null, null, null, null);
throw new Error(e.getMessage(), null, null, null, null);
}
String base64 = null;
if (Conekta.apiKey == null || Conekta.apiKey.isEmpty())
Expand All @@ -65,7 +65,7 @@ private void setHeaders() throws Error {
base64 = Base64.encodeToString(Conekta.apiKey.getBytes("UTF-8"), Base64.NO_WRAP);
this.connection.setRequestProperty("Authorization", "Basic " + base64);
} catch (Exception e) {
throw new Error(e.toString(), null, null, null, null);
throw new Error(e.getMessage(), null, null, null, null);
}

}
Expand Down Expand Up @@ -98,11 +98,11 @@ public Object request(String method, String url, JSONObject params) throws Error
connection.setRequestMethod(method);
this.setHeaders();
} catch (IOException e) {
throw new Error(e.toString(), null, null, null, null);
throw new Error(e.getMessage(), null, null, null, null);
} catch (AuthenticationError e) {
throw new AuthenticationError(e.toString(), e.message_to_purchaser, null, null, null);
} catch (Error e) {
throw new Error(e.toString(), e.message_to_purchaser, null, null, null);
throw new Error(e.getMessage(), e.message_to_purchaser, null, null, null);
}

if (params != null) {
Expand All @@ -121,15 +121,15 @@ public Object request(String method, String url, JSONObject params) throws Error
writer.close();
os.close();
} catch (Exception e) {
throw new Error(e.toString(), null, null, null, null);
throw new Error(e.getMessage(), null, null, null, null);
}

}
int responseCode;
try {
responseCode = connection.getResponseCode();
} catch (Exception e) {
throw new Error(e.toString(), null, null, null, null);
throw new Error(e.getMessage(), null, null, null, null);
}
BufferedReader in;
if (responseCode != 200) {
Expand All @@ -140,7 +140,7 @@ public Object request(String method, String url, JSONObject params) throws Error
in = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
} catch (Exception e) {
throw new Error(e.toString(), null, null, null, null);
throw new Error(e.getMessage(), null, null, null, null);
}
}
String inputLine;
Expand All @@ -163,19 +163,16 @@ public Object request(String method, String url, JSONObject params) throws Error
throw new Error("invalid response: " + response.toString(), null, null, null, null);
// Other
}
in.close();
if (responseCode != 200) {
Error.errorHandler((JSONObject) object, responseCode);
}
in.close();
} catch (Exception e) {
JSONObject error = null;
try {
error = new JSONObject("{'message':'" + URLEncoder.encode(e.toString()) + "'}");
} catch (JSONException ex) {
System.out.println("");
}
Error.errorHandler(error, responseCode);

} catch (IOException e) {
throw new Error(e.getMessage(), null, null, null, null);
} catch (JSONException e) {
throw new Error(e.getMessage(), null, null, null, null);
} catch (Error e) {
throw e;
}
return object;
}
Expand Down
10 changes: 9 additions & 1 deletion test/com/conekta/ErrorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import org.json.JSONException;
import org.json.JSONObject;
import static org.junit.Assert.*;

/**
*
Expand Down Expand Up @@ -80,6 +79,15 @@ public void testParameterValidationError() throws Error, JSONException {
assertTrue(e instanceof ParameterValidationError);
}
}

public void testNoCardError() throws Error, JSONException {
valid_visa_card = new JSONObject("{'card':{'number':'tok_test_visa_4242'}}");
try {
Token token = Token.create(valid_visa_card);
} catch(ParameterValidationError e) {
assertTrue(e instanceof ParameterValidationError);
}
}

public void testProcessingError() throws Error, JSONException {
JSONObject capture = new JSONObject("{'capture': false}");
Expand Down

0 comments on commit dbf7fe0

Please sign in to comment.