diff --git a/.gitignore b/.gitignore index b3d6a6148abb2f7c00d803b78e08508165b8a993..4288729ae58a97160692aba9d1b52be78c660e06 100644 --- a/.gitignore +++ b/.gitignore @@ -89,5 +89,5 @@ fabric.properties log/ target/ testdb/ -tomcat*/ +tomcat.*/ /jams \ No newline at end of file diff --git a/jams-common/src/main/java/net/jami/jams/common/serialization/tomcat/TomcatCustomErrorHandler.java b/jams-common/src/main/java/net/jami/jams/common/serialization/tomcat/TomcatCustomErrorHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..2defb5b0d1501d779a758c48efeb68780f709668 --- /dev/null +++ b/jams-common/src/main/java/net/jami/jams/common/serialization/tomcat/TomcatCustomErrorHandler.java @@ -0,0 +1,40 @@ +/* +* Copyright (C) 2020 by Savoir-faire Linux +* Authors: William Enright <william.enright@savoirfairelinux.com> +* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> +* Johnny Flores <johnny.flores@savoirfairelinux.com> +* Mohammed Raza <mohammed.raza@savoirfairelinux.com> +* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> +* +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ +package net.jami.jams.common.serialization.tomcat; + +import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class TomcatCustomErrorHandler { + + public static void sendCustomError(HttpServletResponse resp,int errorCode, String text){ + try { + resp.setStatus(errorCode); + resp.getOutputStream().write(("{\"error\":\"" + text + "\"}").getBytes()); + } + catch (Exception e){ + log.error("Could not generate an error!"); + } + } +}