Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined detail when endpoint that return a file throws a exception #1533

Open
lucasmsoares96 opened this issue Jan 7, 2025 · 0 comments
Open
Labels
bug 🔥 Something isn't working prioritized 🚚 This issue has been prioritized and will be worked on soon

Comments

@lucasmsoares96
Copy link

Description

The example provided below contains two endpoints:

@app.get(
    "/user/",
)
def read_user() -> UserPublic:
    """Get User."""
    raise HTTPException(
        status_code=404,
        detail="User not found.",#         <<<<<<<<
    )


@app.get(
    "/evidence/",
    response_class=FileResponse,
    responses={
        200: {"content": {"application/zip": {}}},
    },
)
def read_evidence() -> FileResponse:
    """Get Complaint Evidences."""
    raise HTTPException(
        status_code=404,
        detail="Evidence not found.",#         <<<<<<<<
    )

When testing these endpoints using the curl command, everything works fine:

curl -X 'GET' \
  'http://127.0.0.1:8000/user/' \
  -H 'accept: application/json'
{"detail":"User not found."}#         <<<<<<<<

curl -X 'GET' \
  'http://127.0.0.1:8000/evidence/' \
  -H 'accept: application/zip'
{"detail":"Evidence not found."}#         <<<<<<<<

However, when accessing the endpoints using the client generated by OpenAPI-TS, the readUserUserGet function works as expected, but the function readEvidenceEvidenceGet fails to retrieve the detail field in detail="Evidence not found.":

readUserUserGet

try {
	await DefaultService.readUserUserGet({
		throwOnError: true,
	});
} catch (e) {
	if (e instanceof AxiosError && e.response?.data?.detail) {
		console.log(e.response?.data?.detail);//         <<<<<<<<
	} else {
		console.log("detail user undefined");
	}
}

Output:

User not found.

readEvidenceEvidenceGet

try {
	await DefaultService.readEvidenceEvidenceGet({
		throwOnError: true,
	});
} catch (e) {
	if (e instanceof AxiosError && e.response?.data?.detail) {
		console.log(e.response?.data?.detail);
	} else {
		console.log("detail evidence undefined");//         <<<<<<<<
	}
}

Output:

detail evidence undefined

Reproducible example or configuration

https://gitlab.com/lucasmsoares96/DetailBug

OpenAPI specification (optional)

{
"openapi": "3.1.0",
"info": {
"title": "FastAPI",
"version": "0.1.0"
},
"paths": {
"/evidence/": {
"get": {
"summary": "Read Evidence",
"description": "Get Complaint Evidences.",
"operationId": "read_evidence_evidence__get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/zip": {}
}
}
}
}
},
"/user/": {
"get": {
"summary": "Read User",
"description": "Get User.",
"operationId": "read_user_user__get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserPublic"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"UserPublic": {
"properties": {
"name": {
"type": "string",
"title": "Name"
},
"age": {
"type": "integer",
"title": "Age"
}
},
"type": "object",
"required": [
"name",
"age"
],
"title": "UserPublic"
}
}
}
}

System information (optional)

OS: macOS 15.2 24C101 x86_64
Host: MacBookPro11,5
Kernel: 24.2.0
Uptime: 2 days, 2 hours, 20 mins
Packages: 127 (brew)
Shell: zsh 5.9
Resolution: 1440x900@2x
DE: Aqua
WM: Quartz Compositor
WM Theme: Blue (Light)
Terminal: vscode
CPU: Intel i7-4870HQ (8) @ 2.50GHz
GPU: Intel Iris Pro, AMD Radeon R9 M370X
Memory: 10755MiB / 16384MiB

@lucasmsoares96 lucasmsoares96 added the bug 🔥 Something isn't working label Jan 7, 2025
@mrlubos mrlubos added the prioritized 🚚 This issue has been prioritized and will be worked on soon label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working prioritized 🚚 This issue has been prioritized and will be worked on soon
Projects
None yet
Development

No branches or pull requests

2 participants