Skip to content

Commit a523de4

Browse files
committed
handling of invalid api key
1 parent 4a185b8 commit a523de4

3 files changed

Lines changed: 4 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
This is a plugin for [Flow Launcher](https://github.com/Flow-Launcher/Flow.Launcher) that lets you easily see the definitions of words using [wordnik](https://wordnik.com).
33

44
## Get an API Key
5+
To get an API key, head to [developer.wordnik.com](https://developer.wordnik.com/), and create an account. Once you've created your account, you'll be able to fill out a form to request an api key.

SettingsTemplate.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ body:
33
attributes:
44
name: api_key
55
label: Wordnik API Key
6+
description: Head to https://developer.wordnik.com to get your API key.
67
- type: checkbox
78
attributes:
89
name: use_canonical

main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ def query(self, query: str):
117117
}
118118
headers = {"Accept": "application/json"}
119119
res = requests.get(url, params=params, headers=headers)
120+
if res.status_code == 401:
121+
return [self.generate_json(title="Error: Invalid API Key", sub="Click ENTER for instructions on how to get a valid API key", callback="open_url", params=['https://github.com/cibere/Flow.Launcher.Plugin.WordNikDictionary?tab=readme-ov-file#get-an-api-key'])]
120122
res.raise_for_status()
121123
data = res.json()
122124

0 commit comments

Comments
 (0)