From cb46d3a1af498b7d117ff1e5bcf222ad908d5cfe Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 3 Dec 2007 19:45:53 +0000 Subject: [PATCH] Allow the unit to throw InvocationException and do the right thing with it. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4890 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/util/PersistingUnit.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/java/com/threerings/presents/util/PersistingUnit.java b/src/java/com/threerings/presents/util/PersistingUnit.java index f0d8c48d0..ffdd25bbd 100644 --- a/src/java/com/threerings/presents/util/PersistingUnit.java +++ b/src/java/com/threerings/presents/util/PersistingUnit.java @@ -21,12 +21,15 @@ package com.threerings.presents.util; -import com.samskivert.io.PersistenceException; +import java.util.logging.Level; + import com.samskivert.util.Invoker; -import com.threerings.presents.Log; import com.threerings.presents.client.InvocationService; import com.threerings.presents.data.InvocationCodes; +import com.threerings.presents.server.InvocationException; + +import static com.threerings.presents.Log.log; /** * Simplifies a common pattern which is to post an {@link Invoker} unit which does some database @@ -52,7 +55,7 @@ public abstract class PersistingUnit extends Invoker.Unit * will be caught and logged along with the output from {@link #getFailureMessage}, if any. */ public abstract void invokePersistent () - throws PersistenceException; + throws Exception; /** * Handles the success case, which by default is to do nothing. @@ -65,11 +68,14 @@ public abstract class PersistingUnit extends Invoker.Unit * Handles the failure case by logging the error and reporting an internal error to the * listener. */ - public void handleFailure (PersistenceException error) + public void handleFailure (Exception error) { - Log.warning(getFailureMessage()); - Log.logStackTrace(error); - _listener.requestFailed(InvocationCodes.INTERNAL_ERROR); + if (error instanceof InvocationException) { + _listener.requestFailed(error.getMessage()); + } else { + log.log(Level.WARNING, getFailureMessage(), error); + _listener.requestFailed(InvocationCodes.INTERNAL_ERROR); + } } @Override // from Invoker.Unit @@ -77,7 +83,7 @@ public abstract class PersistingUnit extends Invoker.Unit { try { invokePersistent(); - } catch (PersistenceException pe) { + } catch (Exception pe) { _error = pe; } return true; @@ -103,5 +109,5 @@ public abstract class PersistingUnit extends Invoker.Unit } protected InvocationService.InvocationListener _listener; - protected PersistenceException _error; + protected Exception _error; }