Add error response.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 8 Apr 2011 14:50:56 +0000 (16:50 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 8 Apr 2011 14:50:56 +0000 (16:50 +0200)
src/main/java/net/pterodactylus/sone/freenet/fcp/Command.java

index faa10db..2a083ee 100644 (file)
@@ -17,6 +17,7 @@
 
 package net.pterodactylus.sone.freenet.fcp;
 
+import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
 import freenet.support.SimpleFieldSet;
 import freenet.support.api.Bucket;
 
@@ -178,4 +179,36 @@ public interface Command {
 
        }
 
+       /**
+        * Response implementation that can return an error message and an optional
+        * error code.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
+       public class ErrorResponse extends Response {
+
+               /**
+                * Creates a new error response with the given message.
+                *
+                * @param message
+                *            The error message
+                */
+               public ErrorResponse(String message) {
+                       super(new SimpleFieldSetBuilder().put("ErrorMessage", message).get());
+               }
+
+               /**
+                * Creates a new error response with the given code and message.
+                *
+                * @param code
+                *            The error code
+                * @param message
+                *            The error message
+                */
+               public ErrorResponse(int code, String message) {
+                       super(new SimpleFieldSetBuilder().put("ErrorMessage", message).put("ErrorCode", code).get());
+               }
+
+       }
+
 }