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

Give API error responses in JSON format #2685

Open
Kevinjil opened this issue Sep 15, 2024 · 1 comment
Open

Give API error responses in JSON format #2685

Kevinjil opened this issue Sep 15, 2024 · 1 comment

Comments

@Kevinjil
Copy link
Contributor

Description of the enhancement request

Currently, a 404 on an API endpoints gives a HTML page back. This is both wasteful in rendering and annoying to parse on the client / CLI.

The goal you want to achieve

For endpoints which normally return JSON, also return JSON in the non-happy flow.

@nickygerritsen
Copy link
Member

On demoweb it DOES produce JSON:

curl -v https://www.domjudge.org/demoweb/api/contests/test
* Host www.domjudge.org:443 was resolved.
* IPv6: (none)
* IPv4: 192.87.110.101
*   Trying 192.87.110.101:443...
* Connected to www.domjudge.org (192.87.110.101) port 443
* ALPN: curl offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* (304) (IN), TLS handshake, Server hello (2):
* (304) (IN), TLS handshake, Unknown (8):
* (304) (IN), TLS handshake, Certificate (11):
* (304) (IN), TLS handshake, CERT verify (15):
* (304) (IN), TLS handshake, Finished (20):
* (304) (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / AEAD-AES256-GCM-SHA384 / [blank] / UNDEF
* ALPN: server accepted h2
* Server certificate:
*  subject: CN=www.domjudge.org
*  start date: Sep 10 18:18:43 2024 GMT
*  expire date: Dec  9 18:18:42 2024 GMT
*  subjectAltName: host "www.domjudge.org" matched cert's "www.domjudge.org"
*  issuer: C=US; O=Let's Encrypt; CN=R10
*  SSL certificate verify ok.
* using HTTP/2
* [HTTP/2] [1] OPENED stream for https://www.domjudge.org/demoweb/api/contests/test
* [HTTP/2] [1] [:method: GET]
* [HTTP/2] [1] [:scheme: https]
* [HTTP/2] [1] [:authority: www.domjudge.org]
* [HTTP/2] [1] [:path: /demoweb/api/contests/test]
* [HTTP/2] [1] [user-agent: curl/8.7.1]
* [HTTP/2] [1] [accept: */*]
> GET /demoweb/api/contests/test HTTP/2
> Host: www.domjudge.org
> User-Agent: curl/8.7.1
> Accept: */*
>
* Request completely sent off
< HTTP/2 404
< vary: Accept
< cache-control: max-age=0, must-revalidate, private
< date: Sun, 15 Sep 2024 04:49:15 GMT
< content-security-policy: default-src 'self'; style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; script-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; img-src 'self' data: secure.gravatar.com
< x-current-contest:
< expires: Sun, 15 Sep 2024 04:49:15 GMT
< referrer-policy: strict-origin-when-cross-origin
< strict-transport-security: max-age=31556952
< x-content-type-options: nosniff
< x-xss-protection: 1; mode=block
< x-frame-options: DENY
< x-frame-options: DENY
< referrer-policy: same-origin
< x-content-type-options: nosniff
< x-xss-protection: 1; mode=block
< content-type: application/json
< server: Apache/2.4.61 (Debian)
<
* Connection #0 to host www.domjudge.org left intact
{"code":404,"message":"Object with ID 'test' not found"}%

So maybe this is either specific endpoints or only happening in dev-mode?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants