Skip to content

Commit

Permalink
feat: improve error handling
Browse files Browse the repository at this point in the history
ref: #28
ref: #28 (comment)
  • Loading branch information
tbdsux committed May 31, 2023
1 parent e8cde46 commit 94df261
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ https://kuryana.vercel.app/seasonal/{year}/{quarter}
https://kuryana.vercel.app/list/{id}
```

### Error Messages

```js
// mainly on all endpoints except `search`
// sample: /list/unknown-random-id
{
"code": 400,
"error": true,
"description": {
"title": "This list is private.",
"info": "You can see this page because the URL you are accessing cannot be found."
}
}
```

```js
// could also be this (only on `/search`) endpoint
{
"error": true,
"code": 404,
"description": "404 Not Found"
}
```

## Development

- Using the vercel CLI (`localhost:3000`)
Expand Down
16 changes: 13 additions & 3 deletions api/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,19 @@ def res_get_err(self) -> Dict[str, Any]:
err: Dict[str, Any] = {}

try:
err["status_code"] = self.status_code
err["error"] = container.find("div", class_="box-body").find("h1").text
err["info"] = container.find("div", class_="box-body").find("p").text
err["code"] = self.status_code
err["error"] = True
err["description"] = {
"title": container.find("div", class_="box-body")
.find("h1")
.get_text()
.strip(),
"info": container.find("div", class_="box-body")
.find("p")
.get_text()
.strip(),
}

except Exception:
pass

Expand Down
2 changes: 1 addition & 1 deletion api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def fetch_func(query: str, t: str) -> Tuple[int, Dict[str, Any]]:

f = await fs[t].scrape(query=query, t="page")
if not f.ok:
return f.status_code, error(f.status_code, "An unexpected error occurred.")
return f.status_code, f.res_get_err()
else:
f._get()

Expand Down

1 comment on commit 94df261

@vercel
Copy link

@vercel vercel bot commented on 94df261 May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kuryana – ./

kuryana-git-master-theboringdude.vercel.app
kuryana.vercel.app
kuryana-theboringdude.vercel.app

Please sign in to comment.