Browse code

BM-11692 Fix: demote

David Phan authored on 22/06/2017 15:32:42
Showing 2 changed files
... ...
@@ -109,9 +109,14 @@ public class DemoteCommand extends AbstractHSMCommand {
109 109
 		// the message is not archived yet, do the magic
110 110
 		IMAPByteSource mailContent = sc.uidFetchMessage(id.getUid());
111 111
 		Message msg = Mime4JHelper.parse(mailContent.source().openStream());
112
-		hsmId = storage.store(context.getSecurityContext().getContainerUid(), context.getLoginContext().uid,
113
-				mailContent.source().openStream());
114
-		mailContent.close();
112
+		try {
113
+			hsmId = storage.store(context.getSecurityContext().getContainerUid(), context.getLoginContext().uid,
114
+					mailContent.source().openStream());
115
+		} catch (Exception e) {
116
+			throw new IOException("Fail to demote");
117
+		} finally {
118
+			mailContent.close();
119
+		}
115 120
 
116 121
 		try {
117 122
 			// Replace old mail
... ...
@@ -28,6 +28,8 @@ import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder;
28 28
 import com.ning.http.client.HttpResponseHeaders;
29 29
 import com.ning.http.client.generators.InputStreamBodyGenerator;
30 30
 
31
+import net.bluemind.core.api.fault.ServerFault;
32
+
31 33
 public class WriteHandler extends DefaultAsyncHandler<Void> {
32 34
 
33 35
 	private static final Logger logger = LoggerFactory.getLogger(WriteHandler.class);
... ...
@@ -45,6 +47,7 @@ public class WriteHandler extends DefaultAsyncHandler<Void> {
45 47
 	protected Void getResult(int status, HttpResponseHeaders headers, FileBackedOutputStream body) {
46 48
 		if (status != 200) {
47 49
 			logger.warn("PUT {} error: {}", path, status);
50
+			throw new ServerFault();
48 51
 		}
49 52
 		return null;
50 53
 	}