* Sends a Thrift RPC call to the Evernote NoteStore via HTTP POST.
( token: string, writer: ThriftWriter, retryOptions?: Parameters<typeof fetchWithRetry>[2] )
| 62 | * Sends a Thrift RPC call to the Evernote NoteStore via HTTP POST. |
| 63 | */ |
| 64 | async function callNoteStore( |
| 65 | token: string, |
| 66 | writer: ThriftWriter, |
| 67 | retryOptions?: Parameters<typeof fetchWithRetry>[2] |
| 68 | ): Promise<ThriftReader> { |
| 69 | const url = getNoteStoreUrl(token) |
| 70 | |
| 71 | const response = await fetchWithRetry( |
| 72 | url, |
| 73 | { |
| 74 | method: 'POST', |
| 75 | headers: { |
| 76 | 'Content-Type': 'application/x-thrift', |
| 77 | Accept: 'application/x-thrift', |
| 78 | }, |
| 79 | body: new Uint8Array(writer.toBuffer()), |
| 80 | }, |
| 81 | retryOptions |
| 82 | ) |
| 83 | |
| 84 | if (!response.ok) { |
| 85 | throw new Error(`Evernote HTTP ${response.status}: ${response.statusText}`) |
| 86 | } |
| 87 | |
| 88 | const reader = new ThriftReader(await response.arrayBuffer()) |
| 89 | const msg = reader.readMessageBegin() |
| 90 | |
| 91 | if (reader.isException(msg.type)) { |
| 92 | const ex = reader.readException() |
| 93 | throw new Error(`Evernote API error: ${ex.message}`) |
| 94 | } |
| 95 | |
| 96 | return reader |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Checks for Evernote-specific exceptions in response struct fields 1-3. |
no test coverage detected