mirror of
https://github.com/status-im/contract-notifier.git
synced 2025-02-23 16:38:10 +00:00
Error handling for DB
This commit is contained in:
parent
74378d2a8d
commit
5b85a69d2d
@ -27,6 +27,7 @@ class Controller {
|
||||
|
||||
// TODO: handle subscriptions to particular events
|
||||
|
||||
try {
|
||||
const subscriber = await Subscribers.findOne({
|
||||
dappId,
|
||||
address
|
||||
@ -68,7 +69,9 @@ class Controller {
|
||||
token: t.token
|
||||
});
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
}
|
||||
return res.status(200).send("OK");
|
||||
};
|
||||
}
|
||||
@ -96,10 +99,14 @@ class Controller {
|
||||
|
||||
// TODO: handle unsubscribe to particular events
|
||||
|
||||
try {
|
||||
await Subscribers.deleteOne({
|
||||
dappId,
|
||||
address
|
||||
});
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
return res.status(200).send("OK");
|
||||
};
|
||||
@ -116,6 +123,7 @@ class Controller {
|
||||
return next(new BadRequest(errors.array()));
|
||||
}
|
||||
|
||||
try {
|
||||
const verification = await Verifications.findOne({
|
||||
token
|
||||
}).populate("subscriber");
|
||||
@ -136,6 +144,9 @@ class Controller {
|
||||
} else {
|
||||
return next(new BadRequest("Invalid verification token"));
|
||||
}
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
return res.status(200).send("OK");
|
||||
};
|
||||
@ -152,6 +163,7 @@ class Controller {
|
||||
return next(new BadRequest(errors.array()));
|
||||
}
|
||||
|
||||
try {
|
||||
const subscriber = await Subscribers.findOne({
|
||||
dappId,
|
||||
address,
|
||||
@ -159,6 +171,9 @@ class Controller {
|
||||
});
|
||||
|
||||
return res.status(200).json({ isUser: subscriber ? true : false });
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,9 @@ events.on("db:connected", () => {
|
||||
const response = { error: err.message };
|
||||
if (err instanceof BadRequest && err.details) {
|
||||
response.details = err.details;
|
||||
} else {
|
||||
console.error(err);
|
||||
response.error = "Service unavailable";
|
||||
}
|
||||
res.status(err.statusCode).json(response);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user