Sebastian Sdorra avatar Sebastian Sdorra committed 2318d83

send mercurial hook error messages to client

Comments (0)

Files changed (2)

scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/web/HgHookCallbackServlet.java

 
 //~--- non-JDK imports --------------------------------------------------------
 
+import com.google.common.io.Closeables;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
 import com.google.inject.Singleton;
 //~--- JDK imports ------------------------------------------------------------
 
 import java.io.IOException;
+import java.io.PrintWriter;
 
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
       response.sendError(HttpServletResponse.SC_NOT_FOUND);
     }
+    catch (Exception ex)
+    {
+      sendError(response, ex);
+    }
   }
 
   /**
     }
   }
 
+  /**
+   * 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 ----------------------------------------------------------
 
   /**

scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py

       abort = False
     else:
       ui.warn( "ERROR: scm-hook failed with error code " + str(conn.code) + "\n" )
+  except urllib2.URLError, e:
+    msg = e.read();
+    if len(msg) > 0:
+      ui.warn( "ERROR: " + msg)
+    else:
+      ui.warn( "ERROR: scm-hook failed with error code " + str(e.getcode()) + "\n" )
   except ValueError:
     ui.warn( "scm-hook failed with an exception\n" )
   return abort
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.