Skip to content

Commit

Permalink
feat(package/trend): add answer when the Product Hunt developer token…
Browse files Browse the repository at this point in the history
… is not provided
  • Loading branch information
louistiti committed Apr 7, 2019
1 parent 24c153a commit f40b479
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"test:unit": "cross-env PIPENV_PIPFILE=bridges/python/Pipfile jest --silent --projects test/unit/unit.jest.json",
"test:e2e": "npm run test:e2e:nlp-modules && npm run test:e2e:modules",
"test:e2e:modules": "npm run train expressions:en && cross-env PIPENV_PIPFILE=bridges/python/Pipfile jest --silent --verbose --projects test/e2e/modules/e2e.modules.jest.json && npm run train expressions",
"test:e2e:nlp-modules": "npm run train expressions:en && cross-env PIPENV_PIPFILE=bridges/python/Pipfile jest --silent --verbose --setupTestFrameworkScriptFile=./test/paths.setup.js test/e2e/nlp-modules.spec.js && npm run train expressions",
"test:e2e:nlp-modules": "cross-env PIPENV_PIPFILE=bridges/python/Pipfile jest --silent --verbose --setupTestFrameworkScriptFile=./test/paths.setup.js test/e2e/nlp-modules.spec.js && npm run train expressions",
"test:json": "jest --silent --projects test/json/json.jest.json",
"test:module": "babel-node scripts/test-module.js",
"setup:offline": "babel-node scripts/setup-offline/setup-offline.js",
Expand Down
4 changes: 4 additions & 0 deletions packages/trend/data/answers/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
"not_found": [
"There is no product on that date.",
"I did not find any product on that date."
],
"invalid_developer_token": [
"Your Product Hunt developer token is invalid. Please provide a valid one by <a href=\"https://github.com/leon-ai/leon/blob/develop/packages/trend/README.md#product-hunt\" target=\"_blank\">reading this</a>.",
"You did not set a valid Product Hunt developer token. Please set a valid one by <a href=\"https://github.com/leon-ai/leon/blob/develop/packages/trend/README.md#product-hunt\" target=\"_blank\">reading this</a>."
]
}
}
4 changes: 4 additions & 0 deletions packages/trend/data/answers/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
"not_found": [
"Il n'y a pas de produit à cette date.",
"Je n'ai trouvé aucun produit à cette date."
],
"invalid_developer_token": [
"Votre jeton de développeur Product Hunt est invalide. Merci d'en fournir un valide en <a href=\"https://github.com/leon-ai/leon/blob/develop/packages/trend/README.md#product-hunt\" target=\"_blank\">lisant ceci</a>.",
"Vous n'avez pas bien configuré votre jeton de développeur Product Hunt. Veuillez en installer un valide en <a href=\"https://github.com/leon-ai/leon/blob/develop/packages/trend/README.md#product-hunt\" target=\"_blank\">lisant ceci</a>."
]
}
}
7 changes: 6 additions & 1 deletion packages/trend/producthunt.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ def producthunt(string, entities):
url = url + '?day=' + daydate

r = utils.http('GET', url, { 'Authorization': 'Bearer ' + developertoken })
posts = list(enumerate(r.json()['posts']))
response = r.json()

if 'error' in response and response['error'] == 'unauthorized_oauth':
return utils.output('end', 'invalid_developer_token', utils.translate('invalid_developer_token'))

posts = list(enumerate(response['posts']))
result = ''

if len(posts) == 0:
Expand Down
3 changes: 2 additions & 1 deletion packages/trend/test/producthunt.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ describe('trend:producthunt', async () => {
expect([
'reaching',
'today',
'unreachable'
'unreachable',
'invalid_developer_token'
]).toIncludeAnyMembers(global.brain.finalOutput.codes)
})
})
2 changes: 1 addition & 1 deletion server/src/core/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class Brain {
this.socket.emit('is-typing', false)

log.title(packageName)
reject({ type: 'error', obj: data })
reject({ type: 'error', obj: new Error(data) })
})

// Catch the end of the module execution
Expand Down

0 comments on commit f40b479

Please sign in to comment.