ts: Fix uncaught base64 log error (#423)

This commit is contained in:
aac 2021-06-27 12:49:22 +10:00 committed by GitHub
parent 24824ca9f5
commit e5b3f0aa06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -47,7 +47,13 @@ export class EventCoder {
}
public decode(log: string): Event | null {
const logArr = Buffer.from(base64.toByteArray(log));
let logArr: Buffer;
// This will throw if log length is not a multiple of 4.
try {
logArr = Buffer.from(base64.toByteArray(log));
} catch (e){
return null;
}
const disc = base64.fromByteArray(logArr.slice(0, 8));
// Only deserialize if the discriminator implies a proper event.