You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Node.js获取Evernote提醒时遇ThriftException错误求助

Fixing Unhandled Promise Rejection & ThriftException with Evernote API in Node.js

Hey there! As a first-time Node.js developer, it's totally normal to hit these kinds of hiccups when working with third-party APIs. Let's break down what's going wrong and fix your code step by step.

Why You're Seeing These Errors

  1. UnhandledPromiseRejectionWarning: The modern Evernote Node.js SDK returns Promises for async operations, even if you use a callback. If the Promise rejects (like when the API call fails) and you don't handle that rejection, Node.js throws this warning.
  2. ThriftException: This is a generic error from the Evernote API, usually caused by issues like invalid authentication, missing permissions, incorrect API parameters, or mismatched environments (sandbox vs production).

Step-by-Step Fixes

1. Switch to Async/Await with Proper Error Handling

Using async/await makes it easier to manage async code and catch errors cleanly. Here's a revised version of your code with robust error handling:

const token = 'yourToken';
const Evernote = require('evernote');

async function fetchReminderNotes() {
  try {
    // Initialize client: Make sure `sandbox` matches your token's environment!
    // Set to true if using a sandbox token, false for production
    const client = new Evernote.Client({ token: token, sandbox: false });
    const noteStore = client.getNoteStore();

    // Build filter for notes with active reminders
    const noteFilter = new Evernote.NoteStore.NoteFilter({ 
      words: "reminderOrder:*", 
      ascending: true 
    });

    // Specify metadata we want to retrieve
    const resultSpec = {
      includeTitle: true,
      includeReminders: true // Add this to get reminder details like time
    };

    // Fetch notes metadata (await handles the Promise)
    const notesMetadataList = await noteStore.findNotesMetadata(noteFilter, 0, 50, resultSpec);

    // Log results clearly
    console.log(`Found ${notesMetadataList.notes.length} notes with \`reminderOrder\` set.`);
    console.log("\nHere are the notes:");
    notesMetadataList.notes.forEach((note, index) => {
      console.log(`${index + 1}. Title: ${note.title}`);
      if (note.reminder) {
        console.log(`   Reminder Time: ${new Date(note.reminder.time).toLocaleString()}`);
      }
      console.log("---");
    });
  } catch (error) {
    // Catch and log all errors (including ThriftException)
    console.error("Failed to fetch reminder notes:", error);
    if (error.message) {
      console.error("Error Details:", error.message);
    }
    // Common authentication error tip
    if (error.code === 2) {
      console.error("Tip: Double-check your token is valid and has note-reading permissions!");
    }
  }
}

// Run the function
fetchReminderNotes();

2. Verify Your Token & Environment

  • Token Validity: Ensure your token is correct, hasn't expired, and has the note-read permission. You can generate or verify tokens in your Evernote developer dashboard.
  • Sandbox Match: If you generated your token in the Evernote sandbox environment, set sandbox: true in the client initialization. Using a sandbox token with sandbox: false (production) will throw a ThriftException immediately.

3. Confirm Search Syntax

Your reminderOrder:* filter is correct for finding notes with active reminders, but double-check that it aligns with Evernote's official search syntax rules if you run into further issues.

Key Improvements in the Revised Code

  • Error Handling: The try/catch block catches all API errors and Promise rejections, eliminating the unhandled rejection warning entirely.
  • Readability: Async/await replaces nested callbacks, making the code easier to follow and modify.
  • Rich Metadata: Added includeReminders: true to fetch actual reminder details (like the scheduled time) instead of just note titles.

内容的提问来源于stack exchange,提问作者kurokirasama

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:29:33