apexdevkit 1.6.2__tar.gz → 1.6.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/PKG-INFO +1 -1
  2. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/error.py +6 -0
  3. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/fastapi/builder.py +6 -0
  4. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/fastapi/dependable.py +6 -1
  5. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/testing/rest.py +1 -1
  6. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/pyproject.toml +1 -1
  7. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/LICENSE +0 -0
  8. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/README.md +0 -0
  9. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/__init__.py +0 -0
  10. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/annotation/__init__.py +0 -0
  11. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/annotation/deprecate.py +0 -0
  12. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/fastapi/__init__.py +0 -0
  13. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/fastapi/docs.py +0 -0
  14. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/fastapi/resource.py +0 -0
  15. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/fastapi/response.py +0 -0
  16. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/fastapi/router.py +0 -0
  17. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/fastapi/schema.py +0 -0
  18. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/fastapi/service.py +0 -0
  19. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/formatter.py +0 -0
  20. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/http/__init__.py +0 -0
  21. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/http/fake.py +0 -0
  22. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/http/fluent.py +0 -0
  23. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/http/httpx.py +0 -0
  24. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/http/json.py +0 -0
  25. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/http/url.py +0 -0
  26. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/py.typed +0 -0
  27. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/repository/__init__.py +0 -0
  28. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/repository/base.py +0 -0
  29. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/repository/connector.py +0 -0
  30. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/repository/database.py +0 -0
  31. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/repository/in_memory.py +0 -0
  32. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/repository/interface.py +0 -0
  33. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/testing/__init__.py +0 -0
  34. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/testing/database.py +0 -0
  35. {apexdevkit-1.6.2 → apexdevkit-1.6.4}/apexdevkit/testing/fake.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: apexdevkit
3
- Version: 1.6.2
3
+ Version: 1.6.4
4
4
  Summary: Apex Development Tools for python.
5
5
  Author: Apex Dev
6
6
  Author-email: dev@apex.ge
@@ -48,3 +48,9 @@ class ForbiddenError(Exception):
48
48
  @property
49
49
  def id(self) -> Any:
50
50
  return self.item.id
51
+
52
+
53
+ @dataclass
54
+ class ApiError(Exception):
55
+ code: int
56
+ data: dict[str, Any]
@@ -3,7 +3,9 @@ from dataclasses import dataclass, field
3
3
  from typing import Any, Self
4
4
 
5
5
  from fastapi import APIRouter, FastAPI
6
+ from starlette.responses import JSONResponse
6
7
 
8
+ from apexdevkit.error import ApiError
7
9
  from apexdevkit.fastapi.service import RestfulService
8
10
 
9
11
 
@@ -12,6 +14,10 @@ class FastApiBuilder:
12
14
  app: FastAPI = field(default_factory=FastAPI)
13
15
 
14
16
  def build(self) -> FastAPI:
17
+ self.app.add_exception_handler(
18
+ ApiError,
19
+ lambda request, exc: JSONResponse(content=exc.data, status_code=exc.code),
20
+ )
15
21
  return self.app
16
22
 
17
23
  def with_title(self, value: str) -> Self:
@@ -4,7 +4,9 @@ from typing import Annotated, Any, Callable, Protocol, Self
4
4
  from fastapi import Depends, Path
5
5
  from fastapi.requests import Request
6
6
 
7
+ from apexdevkit.error import ApiError, DoesNotExistError
7
8
  from apexdevkit.fastapi import RestfulServiceBuilder
9
+ from apexdevkit.fastapi.response import RestfulResponse
8
10
  from apexdevkit.fastapi.service import RestfulService
9
11
  from apexdevkit.testing import RestfulName
10
12
 
@@ -44,7 +46,10 @@ class ParentDependency:
44
46
  ParentId = Annotated[str, Path(alias=self.parent.singular + "_id")]
45
47
 
46
48
  def _(builder: Builder, parent_id: ParentId) -> RestfulServiceBuilder:
47
- return builder.with_parent(parent_id)
49
+ try:
50
+ return builder.with_parent(parent_id)
51
+ except DoesNotExistError as e:
52
+ raise ApiError(404, RestfulResponse(self.parent).not_found(e))
48
53
 
49
54
  return Annotated[RestfulServiceBuilder, Depends(_)]
50
55
 
@@ -72,7 +72,7 @@ class RestItem(RestResource):
72
72
  assert isinstance(self.http, Httpx), "sub resource only works with Httpx"
73
73
 
74
74
  client = self.http.client
75
- client.base_url = client.base_url.join(self.name.plural)
75
+ client.base_url = client.base_url.join(self.name.singular)
76
76
 
77
77
  return RestItem(self.http, RestfulName(name))
78
78
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "apexdevkit"
3
- version = "1.6.2"
3
+ version = "1.6.4"
4
4
  description = "Apex Development Tools for python."
5
5
  authors = ["Apex Dev <dev@apex.ge>"]
6
6
  readme = "README.md"
File without changes
File without changes