fix enrollment
This commit is contained in:
@@ -1,20 +1,36 @@
|
||||
import json
|
||||
import os
|
||||
from datetime import date
|
||||
from functools import partial
|
||||
from typing import Any
|
||||
|
||||
from aws_lambda_powertools import Logger, Tracer
|
||||
from aws_lambda_powertools.event_handler.api_gateway import (
|
||||
APIGatewayHttpResolver,
|
||||
CORSConfig,
|
||||
Response,
|
||||
content_types,
|
||||
)
|
||||
from aws_lambda_powertools.event_handler.exceptions import ServiceError
|
||||
from aws_lambda_powertools.logging import correlation_paths
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
|
||||
from api_gateway import JSONResponse
|
||||
from middlewares import AuthenticationMiddleware
|
||||
from routes import courses, enrollments, lookup, orders, orgs, settings, users, webhooks
|
||||
|
||||
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, o):
|
||||
if isinstance(o, date):
|
||||
return o.isoformat()
|
||||
|
||||
return super().default(o)
|
||||
|
||||
|
||||
def foo(obj):
|
||||
print(obj)
|
||||
return json.dumps(obj, separators=(',', ':'), cls=JSONEncoder)
|
||||
|
||||
|
||||
tracer = Tracer()
|
||||
logger = Logger(__name__)
|
||||
cors = CORSConfig(
|
||||
@@ -27,6 +43,7 @@ app = APIGatewayHttpResolver(
|
||||
enable_validation=True,
|
||||
cors=cors,
|
||||
debug='AWS_SAM_LOCAL' in os.environ,
|
||||
serializer=partial(json.dumps, separators=(',', ':'), cls=JSONEncoder),
|
||||
)
|
||||
app.use(middlewares=[AuthenticationMiddleware()])
|
||||
app.include_router(courses.router, prefix='/courses')
|
||||
@@ -47,12 +64,11 @@ app.include_router(lookup.router, prefix='/lookup')
|
||||
|
||||
@app.exception_handler(ServiceError)
|
||||
def exc_error(exc: ServiceError):
|
||||
return Response(
|
||||
return JSONResponse(
|
||||
body={
|
||||
'msg': exc.msg,
|
||||
'err': type(exc).__name__,
|
||||
'type': type(exc).__name__,
|
||||
'message': str(exc),
|
||||
},
|
||||
content_type=content_types.APPLICATION_JSON,
|
||||
status_code=exc.status_code,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user