Make a Thrift RPC call to the NoteStore
(token: string, writer: ThriftWriter)
| 78 | |
| 79 | /** Make a Thrift RPC call to the NoteStore */ |
| 80 | async function callNoteStore(token: string, writer: ThriftWriter): Promise<ThriftReader> { |
| 81 | const url = getNoteStoreUrl(token) |
| 82 | const body = writer.toBuffer() |
| 83 | |
| 84 | const response = await fetch(url, { |
| 85 | method: 'POST', |
| 86 | headers: { |
| 87 | 'Content-Type': 'application/x-thrift', |
| 88 | Accept: 'application/x-thrift', |
| 89 | }, |
| 90 | body: new Uint8Array(body), |
| 91 | }) |
| 92 | |
| 93 | if (!response.ok) { |
| 94 | throw new Error(`Evernote API HTTP error: ${response.status} ${response.statusText}`) |
| 95 | } |
| 96 | |
| 97 | const arrayBuffer = await response.arrayBuffer() |
| 98 | const reader = new ThriftReader(arrayBuffer) |
| 99 | const msg = reader.readMessageBegin() |
| 100 | |
| 101 | if (reader.isException(msg.type)) { |
| 102 | const ex = reader.readException() |
| 103 | throw new Error(`Evernote API error: ${ex.message}`) |
| 104 | } |
| 105 | |
| 106 | return reader |
| 107 | } |
| 108 | |
| 109 | /** Check for Evernote-specific exceptions in the response struct. Returns true if handled. */ |
| 110 | function checkEvernoteException(reader: ThriftReader, fieldId: number, fieldType: number): boolean { |
no test coverage detected