Skip to content

Commit

Permalink
Log all API results
Browse files Browse the repository at this point in the history
  • Loading branch information
bobvandevijver committed Aug 20, 2024
1 parent 302813f commit 678ece8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/TuyaOAuth2Client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Homey, { CloudWebhook } from 'homey';
import { fetch, OAuth2Client } from 'homey-oauth2app';
import { nanoid } from 'nanoid';
import { Response } from 'node-fetch';

import { URL } from 'url';
Expand Down Expand Up @@ -261,19 +262,25 @@ export default class TuyaOAuth2Client extends OAuth2Client<TuyaOAuth2Token> {
}

private async _get<T>(path: string): Promise<T> {
const apiUrl = TuyaOAuth2Constants.API_URL[this.getToken().region];
path = `${TuyaOAuth2Constants.API_URL[this.getToken().region]}${path}`;

return this.get({
path: `${apiUrl}${path}`,
const requestId = nanoid();
this.log('GET', requestId, path);
return await this.get<T>({ path }).then(result => {
this.log('GET Response', requestId, JSON.stringify(result));
return result;
});
}

private async _post<T>(path: string, payload?: unknown): Promise<T> {
const apiUrl = TuyaOAuth2Constants.API_URL[this.getToken().region];
path = `${TuyaOAuth2Constants.API_URL[this.getToken().region]}${path}`;

return this.post({
path: `${apiUrl}${path}`,
json: payload,
const requestId = nanoid();
this.log('POST', requestId, path, JSON.stringify(payload));
return await this.post<T>({ path, json: payload }).then(result => {
this.log('POST Response', requestId, JSON.stringify(result));

return result;
});
}

Expand Down
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"dependencies": {
"homey-oauth2app": "^3.5.7",
"nanoid": "3.3.7",
"node-fetch": "^3.3.2",
"source-map-support": "0.5.21"
}
Expand Down

0 comments on commit 678ece8

Please sign in to comment.