private static void ReturnError(CommandExceptionReason reason, string message, HttpListenerResponse response) { switch (reason) { case CommandExceptionReason.Unknown: case CommandExceptionReason.InternalError: response.StatusCode = (int)HttpStatusCode.InternalServerError; return; case CommandExceptionReason.Unauthorized: response.StatusCode = (int)HttpStatusCode.Unauthorized; break; case CommandExceptionReason.MissingRights: case CommandExceptionReason.NotSupported: response.StatusCode = (int)HttpStatusCode.Forbidden; break; case CommandExceptionReason.AmbiguousCall: case CommandExceptionReason.MissingParameter: response.StatusCode = (int)HttpStatusCode.BadRequest; break; case CommandExceptionReason.CommandError: case CommandExceptionReason.NoReturnMatch: case CommandExceptionReason.MissingContext: response.StatusCode = 422; // Unprocessable Entity break; case CommandExceptionReason.FunctionNotFound: response.StatusCode = (int)HttpStatusCode.NotFound; break; default: throw Util.UnhandledDefault(reason); } using (var responseStream = new StreamWriter(response.OutputStream)) responseStream.Write(JsonConvert.SerializeObject(new JsonError(message, reason))); }
private static void ReturnError(CommandExceptionReason reason, string message, HttpListenerResponse response) { switch (reason) { case CommandExceptionReason.Unknown: case CommandExceptionReason.InternalError: response.StatusCode = (int)HttpStatusCode.InternalServerError; return; case CommandExceptionReason.Unauthorized: response.StatusCode = (int)HttpStatusCode.Unauthorized; break; case CommandExceptionReason.MissingRights: case CommandExceptionReason.NotSupported: response.StatusCode = (int)HttpStatusCode.Forbidden; break; case CommandExceptionReason.CommandError: case CommandExceptionReason.AmbiguousCall: case CommandExceptionReason.MissingParameter: case CommandExceptionReason.NoReturnMatch: response.StatusCode = 422; // Unprocessable Entity break; case CommandExceptionReason.FunctionNotFound: response.StatusCode = (int)HttpStatusCode.NotFound; break; default: Log.Write(Log.Level.Debug, "WA Missing Web Error Type"); break; } using (var responseStream = new StreamWriter(response.OutputStream)) responseStream.Write(Util.Serializer.Serialize(new JsonError(message, reason))); }
public CommandException(string message, Exception inner, CommandExceptionReason reason = CommandExceptionReason.Unknown) : base(message, inner) { Reason = reason; }
protected CommandException(CommandExceptionReason reason) { Reason = reason; }
public JsonError(string msg, CommandExceptionReason reason) : base(msg) { ErrorMessage = msg; this.reason = reason; }
public CommandException(string message, CommandExceptionReason reason) : base(message) { Reason = reason; }
public CommandException(string message) : base(message) { Reason = CommandExceptionReason.CommandError; }