Skip to content

Commit

Permalink
revert changes in Message and remove useless if clause in AbsSender
Browse files Browse the repository at this point in the history
  • Loading branch information
Clevero committed Mar 21, 2016
1 parent ac18b95 commit 6ad4491
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ public Message(JSONObject jsonObject) {
if (jsonObject.has(VIDEO_FIELD)) {
this.video = new Video(jsonObject.getJSONObject(VIDEO_FIELD));
}
if(jsonObject.has(AUDIO_FIELD)){
this.audio = new Audio(jsonObject.getJSONObject(AUDIO_FIELD));
}
if (jsonObject.has(CONTACT_FIELD)) {
this.contact = new Contact(jsonObject.getJSONObject(CONTACT_FIELD));
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/telegram/telegrambots/bots/AbsSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -520,16 +520,16 @@ public Message sendAudio(SendAudio sendAudio) throws TelegramApiException {

JSONObject jsonObject = new JSONObject(responseContent);

//if we got an ok, then we can expect a "reseult" section. and out of this can a new Message object be built
if(jsonObject.has("ok") && jsonObject.getBoolean("ok")){
return new Message(jsonObject.getJSONObject("result"));
/* if we got not an "ok" with false, we have a response like that
*
* {"description":"[Error]: Bad Request: chat not found","error_code":400,"ok":false}
*/
if(!jsonObject.getBoolean("ok")){
throw new TelegramApiException("Error at sendAudio", jsonObject.getString("description"));
}

//and if not, there should be a field in our jsonObject that represents a boolean "false" with a key of "ok"
//{"description":"[Error]: Bad Request: chat not found","error_code":400,"ok":false}
// for example. and can throw an exception, cause there was an error...
throw new TelegramApiException("Error at sendAudio", jsonObject.getString("description"));

// and if not, we can expect a "result" section. and out of this can a new Message object be built
return new Message(jsonObject.getJSONObject("result"));
}

/**
Expand Down

0 comments on commit 6ad4491

Please sign in to comment.