mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
send mercurial hook error messages to client
This commit is contained in:
@@ -35,6 +35,7 @@ package sonia.scm.web;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -61,6 +62,7 @@ import sonia.scm.util.Util;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -294,6 +296,10 @@ public class HgHookCallbackServlet extends HttpServlet
|
||||
|
||||
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sendError(response, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -350,6 +356,39 @@ public class HgHookCallbackServlet extends HttpServlet
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param response
|
||||
* @param ex
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private void sendError(HttpServletResponse response, Exception ex)
|
||||
throws IOException
|
||||
{
|
||||
logger.warn("hook ended with exception", ex);
|
||||
response.setStatus(HttpServletResponse.SC_CONFLICT);
|
||||
|
||||
String msg = ex.getMessage();
|
||||
|
||||
if (msg != null)
|
||||
{
|
||||
PrintWriter writer = null;
|
||||
|
||||
try
|
||||
{
|
||||
writer = response.getWriter();
|
||||
writer.println(msg);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Closeables.closeQuietly(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user