33 * Implements only the NoteStore methods needed for the integration.
44 */
55
6- import { createLogger } from '@sim/logger'
76import {
87 ThriftReader ,
98 ThriftWriter ,
@@ -15,8 +14,6 @@ import {
1514 TYPE_STRUCT ,
1615} from './thrift'
1716
18- const logger = createLogger ( 'EvernoteClient' )
19-
2017export interface EvernoteNotebook {
2118 guid : string
2219 name : string
@@ -75,7 +72,8 @@ function extractShardId(token: string): string {
7572/** Get the NoteStore URL for the given token */
7673function getNoteStoreUrl ( token : string ) : string {
7774 const shardId = extractShardId ( token )
78- return `https://www.evernote.com/shard/${ shardId } /notestore`
75+ const host = token . includes ( ':Sandbox' ) ? 'sandbox.evernote.com' : 'www.evernote.com'
76+ return `https://${ host } /shard/${ shardId } /notestore`
7977}
8078
8179/** Make a Thrift RPC call to the NoteStore */
@@ -126,14 +124,31 @@ function checkEvernoteException(reader: ThriftReader, fieldId: number, fieldType
126124 }
127125 if ( fieldId === 2 && fieldType === TYPE_STRUCT ) {
128126 let message = ''
127+ let errorCode = 0
129128 reader . readStruct ( ( r , fid , ftype ) => {
130- if ( fid === 2 && ftype === TYPE_STRING ) {
129+ if ( fid === 1 && ftype === TYPE_I32 ) {
130+ errorCode = r . readI32 ( )
131+ } else if ( fid === 2 && ftype === TYPE_STRING ) {
131132 message = r . readString ( )
132133 } else {
133134 r . skip ( ftype )
134135 }
135136 } )
136- throw new Error ( `Evernote not found: ${ message } ` )
137+ throw new Error ( `Evernote system error (${ errorCode } ): ${ message } ` )
138+ }
139+ if ( fieldId === 3 && fieldType === TYPE_STRUCT ) {
140+ let identifier = ''
141+ let key = ''
142+ reader . readStruct ( ( r , fid , ftype ) => {
143+ if ( fid === 1 && ftype === TYPE_STRING ) {
144+ identifier = r . readString ( )
145+ } else if ( fid === 2 && ftype === TYPE_STRING ) {
146+ key = r . readString ( )
147+ } else {
148+ r . skip ( ftype )
149+ }
150+ } )
151+ throw new Error ( `Evernote not found: ${ identifier } ${ key ? ` (${ key } )` : '' } ` )
137152 }
138153}
139154
0 commit comments