Skip to content

Commit ead7be9

Browse files
authored
Merge pull request #6 from taskbadger/sk/update-gen-code
update gen code + better error handling
2 parents 8367f63 + 1de3478 commit ead7be9

24 files changed

Lines changed: 153 additions & 56 deletions

taskbadger.yaml

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
openapi: 3.0.3
22
info:
3-
title: Task Badger
3+
title: Taskbadger API
44
version: '0.1'
55
description: Documentation for the Task Badger API
66
paths:
@@ -675,6 +675,15 @@ components:
675675
status:
676676
allOf:
677677
- $ref: '#/components/schemas/StatusEnum'
678+
description: |-
679+
* `pending` - pending
680+
* `pre_processing` - pre_processing
681+
* `processing` - processing
682+
* `post_processing` - post_processing
683+
* `success` - success
684+
* `error` - error
685+
* `cancelled` - cancelled
686+
* `stale` - stale
678687
default: pending
679688
value:
680689
type: integer
@@ -712,14 +721,14 @@ components:
712721
minimum: 1
713722
nullable: true
714723
description: Maximum duration the task can be running for before being considered
715-
failed. (minutes)
724+
failed. (seconds)
716725
stale_timeout:
717726
type: integer
718727
maximum: 2147483647
719728
minimum: 1
720729
nullable: true
721730
description: Maximum time to allow between task updates before considering
722-
the task stale. Only applies when task is in a running state. (minutes)
731+
the task stale. (seconds)
723732
StatusEnum:
724733
enum:
725734
- pending
@@ -751,6 +760,15 @@ components:
751760
status:
752761
allOf:
753762
- $ref: '#/components/schemas/StatusEnum'
763+
description: |-
764+
* `pending` - pending
765+
* `pre_processing` - pre_processing
766+
* `processing` - processing
767+
* `post_processing` - post_processing
768+
* `success` - success
769+
* `error` - error
770+
* `cancelled` - cancelled
771+
* `stale` - stale
754772
default: pending
755773
value:
756774
type: integer
@@ -800,14 +818,14 @@ components:
800818
minimum: 1
801819
nullable: true
802820
description: Maximum duration the task can be running for before being considered
803-
failed. (minutes)
821+
failed. (seconds)
804822
stale_timeout:
805823
type: integer
806824
maximum: 2147483647
807825
minimum: 1
808826
nullable: true
809827
description: Maximum time to allow between task updates before considering
810-
the task stale. Only applies when task is in a running state. (minutes)
828+
the task stale. (seconds)
811829
url:
812830
type: string
813831
readOnly: true
@@ -835,6 +853,15 @@ components:
835853
status:
836854
allOf:
837855
- $ref: '#/components/schemas/StatusEnum'
856+
description: |-
857+
* `pending` - pending
858+
* `pre_processing` - pre_processing
859+
* `processing` - processing
860+
* `post_processing` - post_processing
861+
* `success` - success
862+
* `error` - error
863+
* `cancelled` - cancelled
864+
* `stale` - stale
838865
default: pending
839866
value:
840867
type: integer
@@ -872,14 +899,14 @@ components:
872899
minimum: 1
873900
nullable: true
874901
description: Maximum duration the task can be running for before being considered
875-
failed. (minutes)
902+
failed. (seconds)
876903
stale_timeout:
877904
type: integer
878905
maximum: 2147483647
879906
minimum: 1
880907
nullable: true
881908
description: Maximum time to allow between task updates before considering
882-
the task stale. Only applies when task is in a running state. (minutes)
909+
the task stale. (seconds)
883910
required:
884911
- name
885912
securitySchemes:

taskbadger/errors.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class TaskbadgerException(Exception):
2+
pass
3+
4+
5+
class Unauthorized(TaskbadgerException):
6+
pass
7+
8+
9+
class UnexpectedStatus(TaskbadgerException):
10+
def __init__(self, status_code: int, content: bytes):
11+
self.status_code = status_code
12+
self.content = content
13+
14+
super().__init__(f"Unexpected status code: {status_code}")
15+
16+
17+
class ServerError(UnexpectedStatus):
18+
pass

taskbadger/integrations.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import dataclasses
2-
from enum import Enum
32
from typing import Any, Dict
43

54
from taskbadger.exceptions import TaskbadgerException

taskbadger/internal/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" A client library for accessing Task Badger """
1+
""" A client library for accessing Taskbadger API """
22
from .client import AuthenticatedClient, Client
33

44
__all__ = (

taskbadger/internal/api/action_endpoints/action_cancel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ def _get_kwargs(
2929
"headers": headers,
3030
"cookies": cookies,
3131
"timeout": client.get_timeout(),
32+
"follow_redirects": client.follow_redirects,
3233
}
3334

3435

3536
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
3637
if response.status_code == HTTPStatus.NO_CONTENT:
3738
return None
3839
if client.raise_on_unexpected_status:
39-
raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}")
40+
raise errors.UnexpectedStatus(response.status_code, response.content)
4041
else:
4142
return None
4243

taskbadger/internal/api/action_endpoints/action_create.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def _get_kwargs(
3333
"headers": headers,
3434
"cookies": cookies,
3535
"timeout": client.get_timeout(),
36+
"follow_redirects": client.follow_redirects,
3637
"json": json_json_body,
3738
}
3839

@@ -43,7 +44,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Act
4344

4445
return response_201
4546
if client.raise_on_unexpected_status:
46-
raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}")
47+
raise errors.UnexpectedStatus(response.status_code, response.content)
4748
else:
4849
return None
4950

@@ -122,7 +123,7 @@ def sync(
122123
httpx.TimeoutException: If the request takes longer than Client.timeout.
123124
124125
Returns:
125-
Response[Action]
126+
Action
126127
"""
127128

128129
return sync_detailed(
@@ -197,7 +198,7 @@ async def asyncio(
197198
httpx.TimeoutException: If the request takes longer than Client.timeout.
198199
199200
Returns:
200-
Response[Action]
201+
Action
201202
"""
202203

203204
return (

taskbadger/internal/api/action_endpoints/action_get.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def _get_kwargs(
3030
"headers": headers,
3131
"cookies": cookies,
3232
"timeout": client.get_timeout(),
33+
"follow_redirects": client.follow_redirects,
3334
}
3435

3536

@@ -39,7 +40,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Act
3940

4041
return response_200
4142
if client.raise_on_unexpected_status:
42-
raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}")
43+
raise errors.UnexpectedStatus(response.status_code, response.content)
4344
else:
4445
return None
4546

@@ -118,7 +119,7 @@ def sync(
118119
httpx.TimeoutException: If the request takes longer than Client.timeout.
119120
120121
Returns:
121-
Response[Action]
122+
Action
122123
"""
123124

124125
return sync_detailed(
@@ -193,7 +194,7 @@ async def asyncio(
193194
httpx.TimeoutException: If the request takes longer than Client.timeout.
194195
195196
Returns:
196-
Response[Action]
197+
Action
197198
"""
198199

199200
return (

taskbadger/internal/api/action_endpoints/action_list.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def _get_kwargs(
2929
"headers": headers,
3030
"cookies": cookies,
3131
"timeout": client.get_timeout(),
32+
"follow_redirects": client.follow_redirects,
3233
}
3334

3435

@@ -43,7 +44,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Lis
4344

4445
return response_200
4546
if client.raise_on_unexpected_status:
46-
raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}")
47+
raise errors.UnexpectedStatus(response.status_code, response.content)
4748
else:
4849
return None
4950

@@ -117,7 +118,7 @@ def sync(
117118
httpx.TimeoutException: If the request takes longer than Client.timeout.
118119
119120
Returns:
120-
Response[List['Action']]
121+
List['Action']
121122
"""
122123

123124
return sync_detailed(
@@ -186,7 +187,7 @@ async def asyncio(
186187
httpx.TimeoutException: If the request takes longer than Client.timeout.
187188
188189
Returns:
189-
Response[List['Action']]
190+
List['Action']
190191
"""
191192

192193
return (

taskbadger/internal/api/action_endpoints/action_partial_update.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def _get_kwargs(
3434
"headers": headers,
3535
"cookies": cookies,
3636
"timeout": client.get_timeout(),
37+
"follow_redirects": client.follow_redirects,
3738
"json": json_json_body,
3839
}
3940

@@ -44,7 +45,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Act
4445

4546
return response_200
4647
if client.raise_on_unexpected_status:
47-
raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}")
48+
raise errors.UnexpectedStatus(response.status_code, response.content)
4849
else:
4950
return None
5051

@@ -128,7 +129,7 @@ def sync(
128129
httpx.TimeoutException: If the request takes longer than Client.timeout.
129130
130131
Returns:
131-
Response[Action]
132+
Action
132133
"""
133134

134135
return sync_detailed(
@@ -209,7 +210,7 @@ async def asyncio(
209210
httpx.TimeoutException: If the request takes longer than Client.timeout.
210211
211212
Returns:
212-
Response[Action]
213+
Action
213214
"""
214215

215216
return (

taskbadger/internal/api/action_endpoints/action_update.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def _get_kwargs(
3434
"headers": headers,
3535
"cookies": cookies,
3636
"timeout": client.get_timeout(),
37+
"follow_redirects": client.follow_redirects,
3738
"json": json_json_body,
3839
}
3940

@@ -44,7 +45,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Act
4445

4546
return response_200
4647
if client.raise_on_unexpected_status:
47-
raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}")
48+
raise errors.UnexpectedStatus(response.status_code, response.content)
4849
else:
4950
return None
5051

@@ -128,7 +129,7 @@ def sync(
128129
httpx.TimeoutException: If the request takes longer than Client.timeout.
129130
130131
Returns:
131-
Response[Action]
132+
Action
132133
"""
133134

134135
return sync_detailed(
@@ -209,7 +210,7 @@ async def asyncio(
209210
httpx.TimeoutException: If the request takes longer than Client.timeout.
210211
211212
Returns:
212-
Response[Action]
213+
Action
213214
"""
214215

215216
return (

0 commit comments

Comments
 (0)