Skip to content

Commit

Permalink
fix #2790 Enhanced exception logging to warning level in action classes
Browse files Browse the repository at this point in the history
  • Loading branch information
marevol committed Dec 24, 2023
1 parent bedf293 commit c1f8467
Show file tree
Hide file tree
Showing 63 changed files with 391 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.util.stream.Collectors;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codelibs.core.beans.util.BeanUtil;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.Constants;
Expand Down Expand Up @@ -47,6 +49,8 @@
*/
public class AdminAccesstokenAction extends FessAdminAction {

private static final Logger logger = LogManager.getLogger(AdminAccesstokenAction.class);

public static final String ROLE = "admin-accesstoken";

public static final String TOKEN = "token";
Expand Down Expand Up @@ -205,6 +209,7 @@ public HtmlResponse create(final CreateForm form) {
accessTokenService.store(entity);
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand All @@ -225,6 +230,7 @@ public HtmlResponse update(final EditForm form) {
accessTokenService.store(entity);
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand All @@ -246,6 +252,7 @@ public HtmlResponse delete(final EditForm form) {
accessTokenService.delete(entity);
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.nio.file.Files;
import java.nio.file.Path;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codelibs.core.beans.util.BeanUtil;
import org.codelibs.core.concurrent.CommonPoolUtil;
import org.codelibs.fess.Constants;
Expand Down Expand Up @@ -56,6 +58,8 @@ public class AdminBadwordAction extends FessAdminAction {

public static final String ROLE = "admin-badword";

private static final Logger logger = LogManager.getLogger(AdminBadwordAction.class);

// ===================================================================================
// Attribute
// =========
Expand Down Expand Up @@ -208,6 +212,7 @@ public ActionResponse download(final DownloadForm form) {
try (Writer writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(tempFile), getCsvEncoding()))) {
badWordService.exportCsv(writer);
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsFailedToDownloadBadwordFile(GLOBAL), this::asDownloadHtml);
}
try (InputStream in = Files.newInputStream(tempFile)) {
Expand Down Expand Up @@ -244,6 +249,7 @@ public HtmlResponse create(final CreateForm form) {
suggestHelper.addBadWord(entity.getSuggestWord(), false);
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand All @@ -265,6 +271,7 @@ public HtmlResponse update(final EditForm form) {
suggestHelper.storeAllBadWords(false);
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand All @@ -287,6 +294,7 @@ public HtmlResponse delete(final EditForm form) {
suggestHelper.deleteBadWord(entity.getSuggestWord());
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asDetailsHtml);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.codelibs.fess.app.web.admin.boostdoc;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codelibs.core.beans.util.BeanUtil;
import org.codelibs.fess.Constants;
import org.codelibs.fess.annotation.Secured;
Expand Down Expand Up @@ -42,6 +44,8 @@ public class AdminBoostdocAction extends FessAdminAction {

public static final String ROLE = "admin-boostdoc";

private static final Logger logger = LogManager.getLogger(AdminBoostdocAction.class);

// ===================================================================================
// Attribute
// =========
Expand Down Expand Up @@ -185,6 +189,7 @@ public HtmlResponse create(final CreateForm form) {
boostDocumentRuleService.store(entity);
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand All @@ -205,6 +210,7 @@ public HtmlResponse update(final EditForm form) {
boostDocumentRuleService.store(entity);
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand All @@ -226,6 +232,7 @@ public HtmlResponse delete(final EditForm form) {
boostDocumentRuleService.delete(entity);
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.Constants;
import org.codelibs.fess.annotation.Secured;
Expand Down Expand Up @@ -57,6 +59,8 @@ public class AdminDataconfigAction extends FessAdminAction {

public static final String ROLE = "admin-dataconfig";

private static final Logger logger = LogManager.getLogger(AdminDataconfigAction.class);

// ===================================================================================
// Attribute
// =========
Expand Down Expand Up @@ -231,6 +235,7 @@ public HtmlResponse create(final CreateForm form) {
dataConfigService.store(entity);
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand All @@ -251,6 +256,7 @@ public HtmlResponse update(final EditForm form) {
dataConfigService.store(entity);
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand All @@ -272,6 +278,7 @@ public HtmlResponse delete(final EditForm form) {
dataConfigService.delete(entity);
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public HtmlResponse upload(final UploadForm form) {
fileName = fileName.substring(pos + 1);
}
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsDesignFileNameIsInvalid("designFile"), this::asListHtml);
}
}
Expand Down Expand Up @@ -274,7 +275,7 @@ public HtmlResponse update(final EditForm form) {
write(jspFile.getAbsolutePath(), form.content.getBytes(Constants.UTF_8));
saveInfo(messages -> messages.addSuccessUpdateDesignJspFile(GLOBAL, jspFile.getAbsolutePath()));
} catch (final Exception e) {
logger.error("Failed to update {}", form.fileName, e);
logger.warn("Failed to update {}", form.fileName, e);
throwValidationError(messages -> messages.addErrorsFailedToUpdateJspFile(GLOBAL), this::asListHtml);
}
return redirect(getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.io.IOException;
import java.io.InputStream;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codelibs.core.beans.util.BeanUtil;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.Constants;
Expand Down Expand Up @@ -52,6 +54,8 @@ public class AdminDictKuromojiAction extends FessAdminAction {

public static final String ROLE = "admin-dict";

private static final Logger logger = LogManager.getLogger(AdminDictKuromojiAction.class);

// ===================================================================================
// Attribute
// =========
Expand Down Expand Up @@ -258,6 +262,7 @@ public HtmlResponse upload(final UploadForm form) {
try (InputStream inputStream = form.kuromojiFile.getInputStream()) {
file.update(inputStream);
} catch (final IOException e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsFailedToUploadKuromojiFile(GLOBAL),
() -> redirectWith(getClass(), moreUrl("uploadpage/" + form.dictId)));
}
Expand Down Expand Up @@ -285,6 +290,7 @@ public HtmlResponse create(final CreateForm form) {
kuromojiService.store(form.dictId, entity);
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand All @@ -306,6 +312,7 @@ public HtmlResponse update(final EditForm form) {
kuromojiService.store(form.dictId, entity);
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand All @@ -326,6 +333,7 @@ public HtmlResponse delete(final EditForm form) {
kuromojiService.delete(form.dictId, entity);
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codelibs.core.beans.util.BeanUtil;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.Constants;
Expand Down Expand Up @@ -54,6 +56,8 @@ public class AdminDictMappingAction extends FessAdminAction {

public static final String ROLE = "admin-dict";

private static final Logger logger = LogManager.getLogger(AdminDictMappingAction.class);

// ===================================================================================
// Attribute
// =========
Expand Down Expand Up @@ -261,6 +265,7 @@ public HtmlResponse upload(final UploadForm form) {
try (InputStream inputStream = form.charMappingFile.getInputStream()) {
file.update(inputStream);
} catch (final IOException e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsFailedToUploadMappingFile(GLOBAL),
() -> redirectWith(getClass(), moreUrl("uploadpage/" + form.dictId)));
}
Expand All @@ -287,6 +292,7 @@ public HtmlResponse create(final CreateForm form) {
charMappingService.store(form.dictId, entity);
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand All @@ -307,6 +313,7 @@ public HtmlResponse update(final EditForm form) {
charMappingService.store(form.dictId, entity);
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand All @@ -327,6 +334,7 @@ public HtmlResponse delete(final EditForm form) {
charMappingService.delete(form.dictId, entity);
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
} catch (final Exception e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)),
this::asEditHtml);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.io.IOException;
import java.io.InputStream;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codelibs.core.beans.util.BeanUtil;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.Constants;
Expand Down Expand Up @@ -51,6 +53,8 @@ public class AdminDictProtwordsAction extends FessAdminAction {

public static final String ROLE = "admin-dict";

private static final Logger logger = LogManager.getLogger(AdminDictProtwordsAction.class);

// ===================================================================================
// Attribute
// =========
Expand Down Expand Up @@ -256,6 +260,7 @@ public HtmlResponse upload(final UploadForm form) {
try (InputStream inputStream = form.protwordsFile.getInputStream()) {
file.update(inputStream);
} catch (final IOException e) {
logger.warn("Failed to process a request.", e);
throwValidationError(messages -> messages.addErrorsFailedToUploadProtwordsFile(GLOBAL),
() -> redirectWith(getClass(), moreUrl("uploadpage/" + form.dictId)));
}
Expand Down
Loading

0 comments on commit c1f8467

Please sign in to comment.