Skip to content

Commit 981fce3

Browse files
[Python] Add API for testing downstream error code (#545)
1 parent e79b753 commit 981fce3

4 files changed

Lines changed: 15 additions & 0 deletions

File tree

  • sample-apps/python
    • django_frontend_service
    • django_remote_service

sample-apps/python/django_frontend_service/django_frontend_service/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
path('remote-service', views.downstream_service),
1111
path('client-call', views.async_service),
1212
path('mysql', views.mysql),
13+
path('status/<int:code>', views.status),
1314
]

sample-apps/python/django_frontend_service/frontend_service_app/views.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,13 @@ def mysql(request):
186186
logger.error("Could not complete http request to RDS database:" + str(e))
187187
finally:
188188
return get_xray_trace_id()
189+
190+
def status(request, code):
191+
ip = request.GET.get('ip', 'localhost')
192+
ip = ip.replace("/", "")
193+
try:
194+
requests.get(f"http://{ip}:8001/status/{code}")
195+
except Exception:
196+
pass # Ignore exception
197+
logger.info(f"Service A requested status code {code} from Service B")
198+
return get_xray_trace_id()

sample-apps/python/django_remote_service/django_remote_service/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55

66
urlpatterns = [
77
path('healthcheck', views.healthcheck),
8+
path('status/<int:code>', views.status),
89
]

sample-apps/python/django_remote_service/remote_service_app/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44

55
def healthcheck(request):
66
return HttpResponse("Remote service healthcheck")
7+
8+
def status(request, code):
9+
return HttpResponse(status=code)

0 commit comments

Comments
 (0)