Skip to content

Commit

Permalink
Se añade soporte para mostrar respuesta en el mensaje cuando el servi…
Browse files Browse the repository at this point in the history
…dor da algún error 500.
  • Loading branch information
JuanGamezSW committed Mar 21, 2019
1 parent 1c29e39 commit 47a8ce0
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 48 deletions.
4 changes: 2 additions & 2 deletions src/main/java/Utils/Helpers/BuildResponseV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class BuildResponseV1 extends ResponseStamp {
public IResponse getResponse() {
if(!response.trim().isEmpty()) {
if(!response.trim().isEmpty() && status < 500) {
JSONObject body = new JSONObject(response);
if(status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -22,7 +22,7 @@ public IResponse getResponse() {
}
}
else {
return new SuccessV1Response(status, "error", "","Error con código "+status+": "+reason.getReasonPhrase(), reason.getProtocolVersion().getProtocol());
return new SuccessV1Response(status, "error", "","Error con código "+status+": "+reason.getReasonPhrase(), response);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/Utils/Helpers/BuildResponseV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class BuildResponseV2 extends ResponseStamp {
public IResponse getResponse() {
if(!response.trim().isEmpty()) {
if(!response.trim().isEmpty() && status < 500) {
JSONObject body = new JSONObject(response);
if(status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -22,7 +22,7 @@ public IResponse getResponse() {
}
}
else {
return new SuccessV2Response(status, "error", "", "","Error con código "+status+": "+reason.getReasonPhrase(), reason.getProtocolVersion().getProtocol());
return new SuccessV2Response(status, "error", "", "","Error con código "+status+": "+reason.getReasonPhrase(), response);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/Utils/Helpers/BuildResponseV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class BuildResponseV3 extends ResponseStamp {
public IResponse getResponse() {
if(!response.trim().isEmpty()) {
if(!response.trim().isEmpty() && status < 500) {
JSONObject body = new JSONObject(response);
if(status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -22,7 +22,7 @@ public IResponse getResponse() {
}
}
else {
return new SuccessV3Response(status, "error", "","Error con código "+status+": "+reason.getReasonPhrase(), reason.getProtocolVersion().getProtocol());
return new SuccessV3Response(status, "error", "","Error con código "+status+": "+reason.getReasonPhrase(), response);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/Utils/Helpers/BuildResponseV4.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class BuildResponseV4 extends ResponseStamp {
public IResponse getResponse() {
if(!response.trim().isEmpty()) {
if(!response.trim().isEmpty() && status < 500) {
JSONObject body = new JSONObject(response);
if(status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -27,7 +27,7 @@ public IResponse getResponse() {
}
}
else {
return new SuccessV4Response(status, "error", "", "", "", "", "", "", "", "", "", "Error con código "+status+": "+reason.getReasonPhrase(), reason.getProtocolVersion().getProtocol());
return new SuccessV4Response(status, "error", "", "", "", "", "", "", "", "", "", "Error con código "+status+": "+reason.getReasonPhrase(), response);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -88,7 +88,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
}
} else {
return new AceptarRechazarCancelationResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Utils/Requests/Authentication/AuthRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if(!responseString.isEmpty()) {
if(!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if(!body.isNull("messageDetail")){
messageDetail = body.getString("messageDetail");
Expand All @@ -57,7 +57,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
}
}
else{
return new SuccessAuthResponse(status,"error","",0,responseB.getStatusLine().getReasonPhrase(),responseB.getStatusLine().getReasonPhrase());
return new SuccessAuthResponse(status,"error","",0,responseB.getStatusLine().getReasonPhrase(), responseString);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if(!responseString.isEmpty()) {
if(!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -52,7 +52,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
return new BalanceAcctResponse(status, body.getString("status"), body.getString("message"), messageDetail);
}
} else {
return new BalanceAcctResponse(status, "error", responseB.getStatusLine().getReasonPhrase(), responseB.getStatusLine().getReasonPhrase());
return new BalanceAcctResponse(status, "error", responseB.getStatusLine().getReasonPhrase(), responseString);
}

} catch (JSONException e) {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/Utils/Requests/Cancelation/CancelationRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -76,7 +76,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
}
} else {
return new CancelationResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand Down Expand Up @@ -111,7 +111,7 @@ public IResponse sendRequest(IRequest request, boolean isXml) throws GeneralExce
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -131,7 +131,7 @@ public IResponse sendRequest(IRequest request, boolean isXml) throws GeneralExce
}
} else {
return new CancelationResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand Down Expand Up @@ -165,7 +165,7 @@ public IResponse sendRequestPfx(IRequest request) throws ClientProtocolException
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -184,7 +184,7 @@ public IResponse sendRequestPfx(IRequest request) throws ClientProtocolException
}
} else {
return new CancelationResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand All @@ -206,7 +206,7 @@ public IResponse sendRequestUuid(IRequest request) throws ClientProtocolExceptio
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -225,7 +225,7 @@ public IResponse sendRequestUuid(IRequest request) throws ClientProtocolExceptio
}
} else {
return new CancelationResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/Utils/Requests/Csd/CsdRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
String data = body.getString("data");
Expand All @@ -82,7 +82,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
}
} else {
return new CsdResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand All @@ -104,7 +104,7 @@ public IResponse DisableCsdRequest(IRequest request) throws GeneralException, Au
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
String data = body.getString("data");
Expand All @@ -119,7 +119,7 @@ public IResponse DisableCsdRequest(IRequest request) throws GeneralException, Au
}
} else {
return new CsdResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand All @@ -141,7 +141,7 @@ public IResponse GetListCsdRequest(IRequest request) throws GeneralException, Au
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
JSONArray data = body.getJSONArray("data");
Expand All @@ -166,7 +166,7 @@ public IResponse GetListCsdRequest(IRequest request) throws GeneralException, Au
}
} else {
return new ListInfoCsdResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand All @@ -188,7 +188,7 @@ public IResponse GetInfoCsdRequest(IRequest request) throws GeneralException, Au
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -208,7 +208,7 @@ public IResponse GetInfoCsdRequest(IRequest request) throws GeneralException, Au
}
} else {
return new InfoCsdResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Utils/Requests/Pdf/PdfRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
client.close();
responseB.close();
System.out.println(responseString);
if(!responseString.isEmpty()) {
if(!responseString.isEmpty() && statusE < 500) {
JSONObject body = new JSONObject(responseString);
if(statusE==200){
JSONObject data = new JSONObject(body.get("data").toString());
Expand All @@ -79,7 +79,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
}
}
else {
return new PdfResponse(statusE,"error",responseB.getStatusLine().getReasonPhrase(),responseB.getStatusLine().getReasonPhrase());
return new PdfResponse(statusE,"error",responseB.getStatusLine().getReasonPhrase(), responseString);
}
}
catch (JSONException e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public IResponse sendRequest(IRequest request)
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -64,7 +64,7 @@ public IResponse sendRequest(IRequest request)
}
} else {
return new PendientesCancelarResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}

} catch (JSONException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
int codStatus = Integer.parseInt(body.getString("codStatus").trim());
Expand Down Expand Up @@ -104,7 +104,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
}
} else {
return new CfdiRelacionadosResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand Down Expand Up @@ -138,7 +138,7 @@ public IResponse sendRequestPFX(IRequest request) throws ClientProtocolException
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
int codStatus = Integer.parseInt(body.getString("codStatus").trim());
Expand Down Expand Up @@ -181,7 +181,7 @@ public IResponse sendRequestPFX(IRequest request) throws ClientProtocolException
}
} else {
return new CfdiRelacionadosResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand Down Expand Up @@ -215,7 +215,7 @@ public IResponse sendRequestXML(IRequest request) throws GeneralException, AuthE
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
int codStatus = Integer.parseInt(body.getString("codStatus").trim());
Expand Down Expand Up @@ -258,7 +258,7 @@ public IResponse sendRequestXML(IRequest request) throws GeneralException, AuthE
}
} else {
return new CfdiRelacionadosResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand All @@ -281,7 +281,7 @@ public IResponse sendRequestUUID(IRequest request) throws ClientProtocolExceptio
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
int codStatus = Integer.parseInt(body.getString("codStatus").trim());
Expand Down Expand Up @@ -324,7 +324,7 @@ public IResponse sendRequestUUID(IRequest request) throws ClientProtocolExceptio
}
} else {
return new CfdiRelacionadosResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Utils/Requests/Validate/ValidateLcoRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
int statusE = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if(!responseString.isEmpty()) {
if(!responseString.isEmpty() && statusE < 500) {
JSONObject body = new JSONObject(responseString);
if(statusE==200){
JSONObject data = new JSONObject(body.get("data").toString());
Expand All @@ -52,7 +52,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
}
}
else {
return new ValidateLcoResponse(statusE,"error",responseB.getStatusLine().getReasonPhrase(),responseB.getStatusLine().getReasonPhrase());
return new ValidateLcoResponse(statusE,"error",responseB.getStatusLine().getReasonPhrase(), responseString);
}
}
catch (JSONException e){
Expand Down
Loading

0 comments on commit 47a8ce0

Please sign in to comment.