Commit 6afd79f5 authored by Liang Ding's avatar Liang Ding

🎨 细化异常处理

parent 793e6cad
......@@ -49,7 +49,7 @@ import java.util.stream.Collectors;
* Article console request processing.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.2.0.1, Mar 29, 2019
* @version 1.2.0.2, May 18, 2019
* @since 0.4.0
*/
@Singleton
......@@ -498,12 +498,10 @@ public class ArticleConsole {
ret.put(Keys.MSG, langPropsService.get("updateSuccLabel"));
ret.put(Keys.STATUS_CODE, true);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
} catch (final ServiceException e) {
final JSONObject jsonObject = new JSONObject().put(Keys.STATUS_CODE, false);
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("updateFailLabel"));
jsonObject.put(Keys.MSG, e.getMessage());
}
}
......@@ -560,11 +558,9 @@ public class ArticleConsole {
renderer.setJSONObject(ret);
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, e.getMessage());
final JSONObject jsonObject = new JSONObject().put(Keys.STATUS_CODE, false);
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("updateFailLabel"));
jsonObject.put(Keys.MSG, e.getMessage());
}
}
}
......@@ -51,7 +51,7 @@ import java.util.*;
* @author <a href="https://hacpai.com/member/armstrong">ArmstrongCN</a>
* @author <a href="http://zephyr.b3log.org">Zephyr</a>
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @version 1.3.2.13, Apr 24, 2019
* @version 1.3.2.14, May 18, 2019
* @since 0.3.5
*/
@Service
......@@ -252,9 +252,9 @@ public class ArticleQueryService {
* @param articleId the given article id
* @param user the specified user
* @return {@code true} if the current user can access the article, {@code false} otherwise
* @throws Exception exception
* @throws ServiceException service exception
*/
public boolean canAccessArticle(final String articleId, final JSONObject user) throws Exception {
public boolean canAccessArticle(final String articleId, final JSONObject user) throws ServiceException {
if (StringUtils.isBlank(articleId)) {
return false;
}
......@@ -267,10 +267,14 @@ public class ArticleQueryService {
return true;
}
final JSONObject article = articleRepository.get(articleId);
final String currentUserId = user.getString(Keys.OBJECT_ID);
try {
final JSONObject article = articleRepository.get(articleId);
final String currentUserId = user.getString(Keys.OBJECT_ID);
return article.getString(Article.ARTICLE_AUTHOR_ID).equals(currentUserId);
return article.getString(Article.ARTICLE_AUTHOR_ID).equals(currentUserId);
} catch (final Exception e) {
throw new ServiceException(e);
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment