Page MenuHomePhabricator

[Unique Devices] Request with invalid project returns 400 status code instead of 404
Closed, ResolvedPublic2 Estimated Story Points

Description

when request is made with the invalid project as shown in the code below, the unique devices AQS 2.0 endpoint returns 400 instead of 404 as seen in prod environment

prod :

import requests


prod_url = 'https://wikimedia.org/api/rest_v1/metrics/unique-devices/en.wikipedia.org/wiki/.invalid/all-sites/daily/20190529/20200229'

header = {"accept": "application/json",
          "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"}

response = requests.get(prod_url, headers=header)

print(response.status_code)

local ( my port is 8089):

base_url = "http://localhost:8089/metrics/unique-devices/en.wikipedia.org/wiki/.invalid/all-sites/daily/20190529/20200229"

header = {"accept": "application/json",
          "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"}

response = requests.get(base_url, headers=header)

print(response.status_code)

Details

Other Assignee
FGoodwin

Event Timeline

No. Per the MR, it needs to be moved to gerrit for code review.

JArguello-WMF updated Other Assignee, added: FGoodwin; removed: EChukwukere-WMF.
JArguello-WMF added a subscriber: FGoodwin.

test status: QA PASS

PROD URL with invalid project

import requests


prod_url = 'https://wikimedia.org/api/rest_v1/metrics/unique-devices/en.wikipedia.org1/all-sites/daily/20200220/20200225'

header = {"accept": "application/json",
          "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"}

response = requests.get(prod_url, headers=header)

print(response.status_code)
print(response.json())

returns status : 404
returns json:

{'type': 'https://mediawiki.org/wiki/HyperSwitch/errors/not_found', 'title': 'Not found.', 'method': 'get', 'detail': 'The date(s) you used are valid, but we either do not have data for those date(s), or the project you asked for is not loaded yet.  Please check https://wikimedia.org/api/rest_v1/?doc for more information.', 'uri': '/analytics.wikimedia.org/v1/unique-devices/en.wikipedia.org1/all-sites/daily/20200220/20200225'}

Local URL with invalid project

import requests


base_url = "http://localhost:8089/metrics/unique-devices/en.wikipedia.org1/all-sites/daily/20200220/20200225"

header = {"accept": "application/json",
          "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"}

response = requests.get(base_url, headers=header)

print(response.status_code)

print(response.json())

returns status : 404
returns json:

{'detail': ['The date(s) you used are valid, but we either do not have data for those date(s), or the project you asked for is not loaded yet.  Please check documentation for more information.'], 'method': 'get', 'status': 404, 'title': 'Not Found', 'type': 'about:blank', 'uri': '/metrics/unique-devices/en.wikipedia.org1/all-sites/daily/20200220/20200225'}