Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disclose errors in Handlers #142

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;

import static org.swisspush.redisques.util.RedisquesAPI.*;
import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;

/**
* Class AddQueueItemHandler.
*
* @author baldim, https://github.com/mcweba [Marc-Andre Weber]
*/
public class AddQueueItemHandler implements Handler<AsyncResult<Response>> {

private static final Logger log = getLogger(AddQueueItemHandler.class);
private final Message<JsonObject> event;

public AddQueueItemHandler(Message<JsonObject> event) {
Expand All @@ -25,6 +31,7 @@
if(reply.succeeded()){
event.reply(new JsonObject().put(STATUS, OK));
} else {
log.warn("Concealed error", new Exception(reply.cause()));

Check warning on line 34 in src/main/java/org/swisspush/redisques/handler/AddQueueItemHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/swisspush/redisques/handler/AddQueueItemHandler.java#L34

Added line #L34 was not covered by tests
event.reply(new JsonObject().put(STATUS, ERROR));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;

import static org.swisspush.redisques.util.RedisquesAPI.*;

/**
* Class DeleteLockHandler.
*
* @author baldim
*/
public class DeleteLockHandler implements Handler<AsyncResult<Response>> {
private final Message<JsonObject> event;

public DeleteLockHandler(Message<JsonObject> event) {
this.event = event;
}

@Override
public void handle(AsyncResult<Response> reply) {
if (reply.succeeded()) {
event.reply(new JsonObject().put(STATUS, OK));
} else {
event.reply(new JsonObject().put(STATUS, ERROR));
}
}
}
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;

/**
* Class DeleteLockHandler.
*
* @author baldim
*/
public class DeleteLockHandler implements Handler<AsyncResult<Response>> {

private static final Logger log = getLogger(DeleteLockHandler.class);
private final Message<JsonObject> event;

public DeleteLockHandler(Message<JsonObject> event) {
this.event = event;
}

@Override
public void handle(AsyncResult<Response> reply) {
if (reply.succeeded()) {
event.reply(new JsonObject().put(STATUS, OK));
} else {
log.warn("Concealed error", new Exception(reply.cause()));
event.reply(new JsonObject().put(STATUS, ERROR));

Check warning on line 35 in src/main/java/org/swisspush/redisques/handler/DeleteLockHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/swisspush/redisques/handler/DeleteLockHandler.java#L34-L35

Added lines #L34 - L35 were not covered by tests
}
}
}
Original file line number Diff line number Diff line change
@@ -1,44 +1,52 @@
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.swisspush.redisques.util.HandlerUtil;

import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;

import static org.swisspush.redisques.util.RedisquesAPI.*;

/**
* Class GetAllLocksHandler.
*
* @author baldim
*/
public class GetAllLocksHandler implements Handler<AsyncResult<Response>> {

private final Message<JsonObject> event;
private final Optional<Pattern> filterPattern;

public GetAllLocksHandler(Message<JsonObject> event, Optional<Pattern> filterPattern) {
this.event = event;
this.filterPattern = filterPattern;
}

@Override
public void handle(AsyncResult<Response> reply) {
if (reply.succeeded() && reply.result() != null) {
JsonObject result = new JsonObject();
Response locks = reply.result();
List<String> filteredLocks = HandlerUtil.filterByPattern(locks, filterPattern);
result.put("locks", new JsonArray(filteredLocks));
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, result));
} else {
event.reply(new JsonObject().put(STATUS, ERROR));
}
}
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;
import org.swisspush.redisques.util.HandlerUtil;

import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;

import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
import static org.swisspush.redisques.util.RedisquesAPI.VALUE;

/**
* Class GetAllLocksHandler.
*
* @author baldim
*/
public class GetAllLocksHandler implements Handler<AsyncResult<Response>> {

private static final Logger log = getLogger(GetAllLocksHandler.class);
private final Message<JsonObject> event;
private final Optional<Pattern> filterPattern;

public GetAllLocksHandler(Message<JsonObject> event, Optional<Pattern> filterPattern) {
this.event = event;
this.filterPattern = filterPattern;
}

@Override
public void handle(AsyncResult<Response> reply) {
if (reply.succeeded() && reply.result() != null) {
JsonObject result = new JsonObject();
Response locks = reply.result();
List<String> filteredLocks = HandlerUtil.filterByPattern(locks, filterPattern);
result.put("locks", new JsonArray(filteredLocks));
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, result));
} else {
if( reply.failed() ) log.warn("Concealed error", new Exception(reply.cause()));
event.reply(new JsonObject().put(STATUS, ERROR));

Check warning on line 48 in src/main/java/org/swisspush/redisques/handler/GetAllLocksHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/swisspush/redisques/handler/GetAllLocksHandler.java#L48

Added line #L48 was not covered by tests
}
}

}
80 changes: 45 additions & 35 deletions src/main/java/org/swisspush/redisques/handler/GetLockHandler.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;

import static org.swisspush.redisques.util.RedisquesAPI.*;

/**
* Class GetLockHandler.
*
* @author baldim
*/
public class GetLockHandler implements Handler<AsyncResult<Response>> {
private final Message<JsonObject> event;

public GetLockHandler(Message<JsonObject> event) {
this.event = event;
}

@Override
public void handle(AsyncResult<Response> reply) {
if (reply.succeeded()) {
if (reply.result() != null) {
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, reply.result().toString()));
} else {
event.reply(new JsonObject().put(STATUS, NO_SUCH_LOCK));
}
} else {
event.reply(new JsonObject().put(STATUS, ERROR));
}
}
}
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.NO_SUCH_LOCK;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
import static org.swisspush.redisques.util.RedisquesAPI.VALUE;

/**
* Class GetLockHandler.
*
* @author baldim
*/
public class GetLockHandler implements Handler<AsyncResult<Response>> {

private static final Logger log = getLogger(GetLockHandler.class);
private final Message<JsonObject> event;

public GetLockHandler(Message<JsonObject> event) {
this.event = event;
}

@Override
public void handle(AsyncResult<Response> reply) {
if (reply.succeeded()) {
if (reply.result() != null) {
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, reply.result().toString()));
} else {
event.reply(new JsonObject().put(STATUS, NO_SUCH_LOCK));
}
} else {
log.warn("Concealed error", new Exception(reply.cause()));
event.reply(new JsonObject().put(STATUS, ERROR));

Check warning on line 41 in src/main/java/org/swisspush/redisques/handler/GetLockHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/swisspush/redisques/handler/GetLockHandler.java#L40-L41

Added lines #L40 - L41 were not covered by tests
}
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import static org.swisspush.redisques.util.RedisquesAPI.*;
import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
import static org.swisspush.redisques.util.RedisquesAPI.VALUE;

/**
* Class GetQueueItemHandler.
*
* @author baldim, https://github.com/mcweba [Marc-Andre Weber]
*/
public class GetQueueItemHandler implements Handler<AsyncResult<Response>> {

private static final Logger log = getLogger(GetQueueItemHandler.class);
private final Message<JsonObject> event;

public GetQueueItemHandler(Message<JsonObject> event) {
Expand All @@ -24,7 +32,9 @@ public void handle(AsyncResult<Response> reply) {
if (reply.succeeded() && reply.result() != null) {
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, reply.result().toString()));
} else {
if( reply.failed() ) log.warn("Concealed error", new Exception(reply.cause()));
event.reply(new JsonObject().put(STATUS, ERROR));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;

import static org.swisspush.redisques.util.RedisquesAPI.*;
import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
import static org.swisspush.redisques.util.RedisquesAPI.VALUE;

/**
* Class GetQueueItemsCountHandler.
*
* @author https://github.com/mcweba [Marc-Andre Weber]
*/
public class GetQueueItemsCountHandler implements Handler<AsyncResult<Response>> {

private static final Logger log = getLogger(GetQueueItemsCountHandler.class);
private final Message<JsonObject> event;

public GetQueueItemsCountHandler(Message<JsonObject> event) {
Expand All @@ -26,6 +33,7 @@
Long queueItemCount = reply.result().toLong();
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, queueItemCount));
} else {
log.warn("Concealed error", new Exception(reply.cause()));

Check warning on line 36 in src/main/java/org/swisspush/redisques/handler/GetQueueItemsCountHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/swisspush/redisques/handler/GetQueueItemsCountHandler.java#L36

Added line #L36 was not covered by tests
event.reply(new JsonObject().put(STATUS, ERROR));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonArray;

import static org.swisspush.redisques.util.RedisquesAPI.*;

import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.INFO;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
import static org.swisspush.redisques.util.RedisquesAPI.VALUE;

/**
* Class GetQueueItemsHandler.
*
* @author baldim, https://github.com/mcweba [Marc-Andre Weber]
*/
public class GetQueueItemsHandler implements Handler<AsyncResult<Response>> {

private static final Logger log = getLogger(GetQueueItemsHandler.class);
private final Message<JsonObject> event;
private final Long queueItemCount;

Expand All @@ -39,7 +46,9 @@
}
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, values).put(INFO, countInfo));
} else {
log.warn("Concealed error", new Exception(reply.cause()));

Check warning on line 49 in src/main/java/org/swisspush/redisques/handler/GetQueueItemsHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/swisspush/redisques/handler/GetQueueItemsHandler.java#L49

Added line #L49 was not covered by tests
event.reply(new JsonObject().put(STATUS, ERROR));
}
}

}
Loading
Loading