@@ -27,7 +27,7 @@ class Bring {
2727 }
2828 } ) ;
2929 } catch ( e ) {
30- throw `Cannot Login: ${ e } ` ;
30+ throw new Error ( `Cannot Login: ${ e . message } ` ) ;
3131 } // endCatch
3232
3333 data = JSON . parse ( data ) ;
@@ -39,49 +39,47 @@ class Bring {
3939 this . headers [ `X-BRING-USER-UUID` ] = this . uuid ;
4040 this . headers [ `Authorization` ] = `Bearer ${ this . bearerToken } ` ;
4141 this . putHeaders = { ...this . headers , ...{ 'Content-Type' : `application/x-www-form-urlencoded; charset=UTF-8` } } ;
42-
43- return Promise . resolve ( ) ;
4442 } // endLogin
4543
4644 /**
4745 * Loads all shopping lists
4846 *
49- * @return {json }
47+ * @return {Promise< json> }
5048 */
5149 async loadLists ( ) {
5250 try {
5351 const data = await request ( `${ this . url } bringusers/${ this . uuid } /lists` , { headers : this . headers } ) ;
54- return Promise . resolve ( JSON . parse ( data ) ) ;
52+ return JSON . parse ( data ) ;
5553 } catch ( e ) {
56- return Promise . reject ( `Cannot get lists: ${ e } ` ) ;
54+ throw new Error ( `Cannot get lists: ${ e . message } ` ) ;
5755 } // endCatch
5856 } // endLoadLists
5957
6058 /**
6159 * Get all items from the current selected shopping list
6260 *
63- * @return {json }
61+ * @return {Promise< json> }
6462 */
6563 async getItems ( listUuid ) {
6664 try {
6765 const data = await request ( `${ this . url } bringlists/${ listUuid } ` , { headers : this . headers } ) ;
68- return Promise . resolve ( JSON . parse ( data ) ) ;
66+ return JSON . parse ( data ) ;
6967 } catch ( e ) {
70- return Promise . reject ( `Cannot get items for list ${ listUuid } : ${ e } ` ) ;
68+ throw new Error ( `Cannot get items for list ${ listUuid } : ${ e . message } ` ) ;
7169 } // endCatch
7270 } // endGetItems
7371
7472 /**
7573 * Get detailed information about all items from the current selected shopping list
7674 *
77- * @return {json }
75+ * @return {Promise< json> }
7876 */
7977 async getItemsDetails ( listUuid ) {
8078 try {
8179 const data = await request ( `${ this . url } bringlists/${ listUuid } /details` , { headers : this . headers } ) ;
82- return Promise . resolve ( JSON . parse ( data ) ) ;
80+ return JSON . parse ( data ) ;
8381 } catch ( e ) {
84- return Promise . reject ( `Cannot get detailed items for list ${ listUuid } : ${ e } ` ) ;
82+ throw new Error ( `Cannot get detailed items for list ${ listUuid } : ${ e . message } ` ) ;
8583 } // endCatch
8684 } // endGetItemsDetails
8785
@@ -91,17 +89,17 @@ class Bring {
9189 * @param {string } itemName The name of the item you want to send to the bring server
9290 * @param {string } specification The litte description under the name of the item
9391 * @param {string } listUuid The lisUUID you want to receive a list of users from.
94- * @return should return an empty string and answerHttpStatus should contain 204. If not -> error
92+ * @return { Promise<string> } should return an empty string and answerHttpStatus should contain 204. If not -> error
9593 */
9694 async saveItem ( listUuid , itemName , specification ) {
9795 try {
9896 const data = await request . put ( `${ this . url } bringlists/${ listUuid } ` , {
9997 headers : this . putHeaders ,
10098 body : `&purchase=${ itemName } &recently=&specification=${ specification } &remove=&sender=null`
10199 } ) ;
102- return Promise . resolve ( data ) ;
100+ return data ;
103101 } catch ( e ) {
104- return Promise . reject ( `Cannot save item ${ itemName } (${ specification } ) to ${ listUuid } : ${ e } ` ) ;
102+ throw new Error ( `Cannot save item ${ itemName } (${ specification } ) to ${ listUuid } : ${ e . message } ` ) ;
105103 } // endCatch
106104 } // endSaveItem
107105
@@ -110,17 +108,17 @@ class Bring {
110108 *
111109 * @param {string } itemName Name of the item you want to delete from you shopping list
112110 * @param {string } listUuid The lisUUID you want to receive a list of users from.
113- * @return should return an empty string and $answerHttpStatus should contain 204. If not -> error
111+ * @return { Promise<string> } should return an empty string and $answerHttpStatus should contain 204. If not -> error
114112 */
115113 async removeItem ( listUuid , itemName ) {
116114 try {
117115 const data = await request . put ( `${ this . url } bringlists/${ listUuid } ` , {
118116 headers : this . putHeaders ,
119117 body : `&purchase=&recently=&specification=&remove=${ itemName } &sender=null`
120118 } ) ;
121- return Promise . resolve ( data ) ;
119+ return data ;
122120 } catch ( e ) {
123- return Promise . reject ( `Cannot remove item ${ itemName } from ${ listUuid } : ${ e } ` ) ;
121+ throw new Error ( `Cannot remove item ${ itemName } from ${ listUuid } : ${ e . message } ` ) ;
124122 } // endCatch
125123 } // endRemoveItem
126124
@@ -129,89 +127,88 @@ class Bring {
129127 *
130128 * @param {string } itemName Name of the item you want to delete from you shopping list
131129 * @param {string } listUuid The lisUUID you want to receive a list of users from.
132- * @return should return an empty string and $answerHttpStatus should contain 204. If not -> error
130+ * @return { Promise<string> } should return an empty string and $answerHttpStatus should contain 204. If not -> error
133131 */
134132 async moveToRecentList ( listUuid , itemName ) {
135133 try {
136134 const data = await request . put ( `${ this . url } bringlists/${ listUuid } ` , {
137135 headers : this . putHeaders ,
138136 body : `&purchase=&recently=${ itemName } &specification=&remove=&&sender=null`
139137 } ) ;
140- return Promise . resolve ( data ) ;
138+ return data ;
141139 } catch ( e ) {
142- return Promise . reject ( `Cannot remove item ${ itemName } from ${ listUuid } : ${ e } ` ) ;
140+ throw new Error ( `Cannot remove item ${ itemName } from ${ listUuid } : ${ e . message } ` ) ;
143141 } // endCatch
144142 } // endRemoveItem
145143
146144 /**
147145 * Get all users from a shopping list
148146 *
149147 * @param {string } listUuid The lisUUID you want to receive a list of users from.
150- * @return {json }
148+ * @return {Promise< json> }
151149 */
152150 async getAllUsersFromList ( listUuid ) {
153151 try {
154152 const data = await request ( `${ this . url } bringlists/${ listUuid } /users` , { headers : this . headers } ) ;
155- return Promise . resolve ( JSON . parse ( data ) ) ;
153+ return JSON . parse ( data ) ;
156154 } catch ( e ) {
157- return Promise . reject ( `Cannot get users from list: ${ e } ` ) ;
155+ throw new Error ( `Cannot get users from list: ${ e . message } ` ) ;
158156 } // endCatch
159157 } // endGetAllUsersFromList
160158
161-
162159 /**
163- * @return {json }
160+ * @return {Promise< json> }
164161 */
165162 async getUserSettings ( ) {
166163 try {
167164 const data = await request ( `${ this . url } bringusersettings/${ this . uuid } ` , { headers : this . headers } ) ;
168- return Promise . resolve ( JSON . parse ( data ) ) ;
165+ return JSON . parse ( data ) ;
169166 } catch ( e ) {
170- return Promise . reject ( `Cannot get user settings: ${ e } ` ) ;
167+ throw new Error ( `Cannot get user settings: ${ e . message } ` ) ;
171168 } // endCatch
172169 } // endGetUserSettings
173170
174171 /**
175172 * Load translation file e. g. via 'de-DE'
176173 * @param {string } locale from which country translations will be loaded
177- * @return {json } translations
174+ * @return {Promise< json> } translations
178175 */
179176 async loadTranslations ( locale ) {
180177 try {
181178 const data = await request ( `https://web.getbring.com/locale/articles.${ locale } .json` ) ;
182- return Promise . resolve ( JSON . parse ( data ) ) ;
179+ return JSON . parse ( data ) ;
183180 } catch ( e ) {
184- return Promise . reject ( `Cannot get translations: ${ e } ` ) ;
181+ throw new Error ( `Cannot get translations: ${ e . message } ` ) ;
185182 } // endCatch
186183 } // endLoadTranslations
187184
188185 /**
189186 * Load translation file e. g. via 'de-DE'
190187 * @param {string } locale from which country translations will be loaded
191- * @return { json } catalog
188+ * @return @return { Promise< json> } catalog
192189 */
193190 async loadCatalog ( locale ) {
194191 try {
195192 const data = await request ( `https://web.getbring.com/locale/catalog.${ locale } .json` ) ;
196- return Promise . resolve ( JSON . parse ( data ) ) ;
193+ return JSON . parse ( data ) ;
197194 } catch ( e ) {
198- return Promise . reject ( `Cannot get catalog: ${ e } ` ) ;
195+ throw new Error ( `Cannot get catalog: ${ e . message } ` ) ;
199196 } // endCatch
200197 } // endLoadCatalog
201198
202199 /**
203200 * Get pending invitations
204- * @return {json } pending invitations
201+ * @return {Promise< json> } pending invitations
205202 */
206203 async getPendingInvitations ( ) {
207204 try {
208205 const data = await request ( `${ this . url } bringusers/${ this . uuid } /invitations?status=pending` , { headers : this . headers } ) ;
209- return Promise . resolve ( JSON . parse ( data ) ) ;
206+ return JSON . parse ( data ) ;
210207 } catch ( e ) {
211- return Promise . reject ( `Cannot get pending invitations: ${ e } ` ) ;
208+ throw new Error ( `Cannot get pending invitations: ${ e } ` ) ;
212209 } // endCatch
213210 } // endGetPendingInvitations
214211
215212} // endClassBring
216213
217- module . exports = Bring ;
214+ module . exports = Bring ;
0 commit comments