JavaScript
Promise vs async/await

by Gregor Herdmann

return this.cryptobox.decrypt(sessionId, messageBytes.buffer)
  .then(value => ({isSuccess: true, value}))
  .catch(error => {
      const isOutdatedMessage = error.code === ProteusErrors.DecryptError.CODE.CASE_208;
      const isDuplicateMessage = error.code === ProteusErrors.DecryptError.CODE.CASE_209;

      if (isOutdatedMessage || isDuplicateMessage) {
        return {error, isSuccess: false};
      }

      throw error;
  });

try {
  const result = await this.cryptobox.decrypt(sessionId, messageBytes.buffer);
  return {isSuccess: true, value: result};
} catch (error) {
  const isOutdatedMessage = error.code === ProteusErrors.DecryptError.CODE.CASE_208;
  const isDuplicateMessage = error.code === ProteusErrors.DecryptError.CODE.CASE_209;

  if (isOutdatedMessage || isDuplicateMessage) {
    return {error, isSuccess: false};
  }

  throw error;
}