Skip to content

Commit

Permalink
Don't require parseCSVResult to return a Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
tyscorp committed Dec 19, 2016
1 parent 5158b25 commit fd13734
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mws.Orders.ListOrders({
Flat files:
When working with a flat-file response from Amazon, a `parseCSVResult` function is provided as an
option to conviniently post-process the result. *It must return a Promise*.
option to conviniently post-process the result. Returning a Promise will result in the Promise being resolved.
```javascript
// An example to change the encoding of the raw response
Expand All @@ -69,7 +69,7 @@ const mws = new MWSClient({
secretAccessKey: 'kek',
merchantId: 'hue',
meta: {
parseCSVResult: (data) => Promise.resolve(iconv.encode(data, 'utf-8').toString())
parseCSVResult: (data) => iconv.encode(data, 'utf-8').toString()
}
});
```
5 changes: 3 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AmazonMwsClient {
max_attempts: Infinity,
attempt: -1,
contentType: 'application/x-www-form-urlencoded',
parseCSVResult: (data) => Promise.resolve(data)
parseCSVResult: (data) => data
}
});

Expand Down Expand Up @@ -131,7 +131,8 @@ class AmazonMwsClient {
const body = response.body;

if (body.slice(0, 5) !== '<?xml') {
return meta.parseCSVResult(body).then((result) => ({ result, metadata: null }));
return Promise.resolve(meta.parseCSVResult(body))
.then((result) => ({ result, metadata: null }));
}

const data = JSON.parse(parser.toJson(body));
Expand Down

0 comments on commit fd13734

Please sign in to comment.