Skip to content

Commit

Permalink
解决无数据对应 NotExistException 会对外返回异常而不是空值
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon committed Oct 9, 2022
1 parent c76dccd commit f84c6de
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
37 changes: 22 additions & 15 deletions APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,11 @@ public AbstractObjectParser setSQLConfig(int count, int page, int position) thro
try {
sqlConfig = newSQLConfig(false);
}
catch (NotExistException e) {
e.printStackTrace();
return this;
catch (Exception e) {
if (e instanceof NotExistException || (e instanceof CommonException && e.getCause() instanceof NotExistException)) {
return this;
}
throw e;
}
}
sqlConfig.setCount(sqlConfig.getCount() <= 0 ? count : sqlConfig.getCount()).setPage(page).setPosition(position);
Expand Down Expand Up @@ -722,18 +724,23 @@ public AbstractObjectParser executeSQL() throws Exception {
try {
sqlReponse = onSQLExecute();
}
catch (NotExistException e) {
// Log.e(TAG, "getObject try { response = getSQLObject(config2); } catch (Exception e) {");
// if (e instanceof NotExistException) {//非严重异常,有时候只是数据不存在
// // e.printStackTrace();
sqlReponse = null;//内部吃掉异常,put到最外层
// requestObject.put(JSONResponse.KEY_MSG
// , StringUtil.getString(requestObject.get(JSONResponse.KEY_MSG)
// + "; query " + path + " cath NotExistException:"
// + newErrorResult(e).getString(JSONResponse.KEY_MSG)));
// } else {
// throw e;
// }
catch (Exception e) {
if (e instanceof NotExistException || (e instanceof CommonException && e.getCause() instanceof NotExistException)) {
// Log.e(TAG, "getObject try { response = getSQLObject(config2); } catch (Exception e) {");
// if (e instanceof NotExistException) {//非严重异常,有时候只是数据不存在
// // e.printStackTrace();
sqlReponse = null;//内部吃掉异常,put到最外层
// requestObject.put(JSONResponse.KEY_MSG
// , StringUtil.getString(requestObject.get(JSONResponse.KEY_MSG)
// + "; query " + path + " cath NotExistException:"
// + newErrorResult(e).getString(JSONResponse.KEY_MSG)));
// } else {
// throw e;
// }
}
else {
throw e;
}
}
}

Expand Down
16 changes: 5 additions & 11 deletions APIJSONORM/src/main/java/apijson/orm/AbstractParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

package apijson.orm;

import static apijson.JSONObject.KEY_EXPLAIN;
import static apijson.RequestMethod.GET;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.UnsupportedEncodingException;
import java.lang.management.ManagementFactory;
Expand All @@ -24,29 +24,23 @@
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.TimeoutException;

import javax.activation.UnsupportedDataTypeException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.Query;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import apijson.JSON;
import apijson.JSONRequest;
import apijson.JSONResponse;
import apijson.Log;
import apijson.NotNull;
import apijson.RequestMethod;
import apijson.StringUtil;
import apijson.orm.exception.ConditionErrorException;
import apijson.orm.exception.ConflictException;
import apijson.orm.exception.CommonException;
import apijson.orm.exception.NotExistException;
import apijson.orm.exception.NotLoggedInException;
import apijson.orm.exception.OutOfRangeException;

import static apijson.JSONObject.KEY_EXPLAIN;
import static apijson.RequestMethod.GET;

/**parser for parsing request to JSONObject
* @author Lemon
Expand Down

0 comments on commit f84c6de

Please sign in to comment.