Skip to content

Commit

Permalink
🐛fixed some exception problems.
Browse files Browse the repository at this point in the history
  • Loading branch information
genshen committed Oct 12, 2017
1 parent 057a455 commit 2850fee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
16 changes: 11 additions & 5 deletions http-ustb/src/main/java/me/gensh/helloustb/http/HttpClients.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ public HttpClients request(String url, int requestType, String charset, Map<Stri
br = new BufferedReader(new InputStreamReader(is, charset)); //remember to close it after finishing its usage.
return this;
} else {
throw new PendingException();
throw new PendingException("got null InputStream while http POST request.");
}
} catch (IOException e) {
throw new PendingException();
PendingException pe = new PendingException(e.getMessage());
pe.setStackTrace(e.getStackTrace());
throw pe; //throw exception to higher level.
}
} else { // (requestType == HTTP_GET) process get response sa default.
try { //initial BufferedReader for GET ,or throw PendingException.
Expand All @@ -95,10 +97,12 @@ public HttpClients request(String url, int requestType, String charset, Map<Stri
br = new BufferedReader(new InputStreamReader(is, charset)); //remember to close it after finishing its usage.
return this;
} else {// maybe connection timeout error
throw new PendingException();
throw new PendingException("got null InputStream while http GET request.");
}
} catch (IOException e) {
throw new PendingException();
PendingException pe = new PendingException(e.getMessage());
pe.setStackTrace(e.getStackTrace());
throw pe; //throw exception to higher level.
}
}
}
Expand All @@ -122,7 +126,9 @@ public ResolvedData resolve(int requestType, int id) throws ResponseResolveExcep
return resolvedData;
}
} catch (IOException e) {
throw new ResponseResolveException();
ResponseResolveException re = new ResponseResolveException(e.getMessage());
re.setStackTrace(e.getStackTrace());
throw re; //throw exception to higher level.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@

public class PendingException extends IOException {

public PendingException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
*/

public class ResponseResolveException extends IOException {

public ResponseResolveException(String message) {
super(message);
}
}

0 comments on commit 2850fee

Please sign in to comment.