Skip to content

Commit

Permalink
fix: fix error when msg.space is empty (#140)
Browse files Browse the repository at this point in the history
* fix: fix error when msg.space is empty

* fix: validate message before reading

* chore: refactoring
  • Loading branch information
wa0x6e authored Aug 28, 2023
1 parent f34fd8d commit 33a359c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,20 @@ router.get('/api/messages/:hash', async (req, res) => {
});

router.post('/', async (req, res) => {
if (!req.body.data || !req.body.data.message) {
const msg = req.body.data?.message;

if (!msg) {
return res.status(400).json({
error: 'Invalid format request'
});
}

if (!req.body.data.types.Space && !msg.settings && !msg.space) {
return res.status(400).json({
error: 'Missing space'
});
}

let address;
try {
address = getAddress(req.body.address);
Expand All @@ -82,7 +90,6 @@ router.post('/', async (req, res) => {
}

try {
const msg = req.body.data.message;
const msgHash = snapshot.utils.getHash(req.body.data);
const env = 'livenet';
let network = env === 'livenet' ? '1' : '5';
Expand Down

0 comments on commit 33a359c

Please sign in to comment.