Skip to content

Commit

Permalink
More tests and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervonb committed Jul 17, 2024
1 parent 2268103 commit 7ccc454
Show file tree
Hide file tree
Showing 4 changed files with 339 additions and 157 deletions.
9 changes: 8 additions & 1 deletion nats/micro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@
# limitations under the License.
#

from dataclasses import replace
from nats.aio.client import Client
from typing import Optional

from .service import Service, ServiceConfig
from .request import Request, Handler


async def add_service(nc: Client, config: ServiceConfig) -> Service:
async def add_service(nc: Client, config: Optional[ServiceConfig] = None, **kwargs) -> Service:
"""Add a service."""
if config:
config = replace(config, **kwargs)
else:
config = ServiceConfig(**kwargs)

service = Service(nc, config)
await service.start()

Expand Down
6 changes: 5 additions & 1 deletion nats/micro/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ async def respond_error(
:param data: The error data.
:param headers: Additional response headers.
"""
headers = headers or {}
if headers:
headers = headers.copy()
else:
headers = {}

headers.update(
{
ERROR_HEADER: description,
Expand Down
Loading

0 comments on commit 7ccc454

Please # to comment.