ocket8888 opened a new issue #5033:
URL: https://github.com/apache/trafficcontrol/issues/5033
## I'm submitting a ...
- bug report
## Traffic Control components affected ...
- Traffic Ops
## Current behavior:
Trying to assign a Delivery Service Request which does not exist to any user
will result in an Internal Server error.
## Expected / new behavior:
If a resource is not found, the API should communicate that with the `404
Not Found` HTTP status code.
## Minimal reproduction of the problem with instructions:
Given that no Delivery Service Request exists with the ID 1, attempt to
assign Delivery Service Request 1 to any (existing) user. I used my own user
(who had the ID 9 in the following example) and it looks like this:
### Request
```http
PUT /api/2.0/deliveryservice_requests/1/assign HTTP/1.1
User-Agent: python-requests/2.22.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Cookie: mojolicious=...
Content-Length: 15
{"assigneeId": 9}
```
(Note also that the documentation specifies a required "id" property of the
request body - that is not correct. The DSR to be assigned is fully identified
by the request URI.)
### Response
```http
HTTP/1.1 500 Internal Server Error
Content-Encoding: gzip
Content-Type: application/json
Set-Cookie: mojolicious=...
Vary: Accept-Encoding
X-Server-Name: traffic_ops_golang/
Date: Tue, 15 Sep 2020 23:34:43 GMT
Content-Length: 83
{
"alerts": [
{
"text": "Internal Server Error",
"level": "error"
}
]
}
```
## Anything else:
From the stack trace I found:
```
INFO: routing.go:249: 2020-09-15T23:26:42.644209507Z: PUT
/api/2.0/deliveryservice_requests/1/assign? handling (reqid 33624)
DEBUG: plugin.go:190: 2020-09-15T23:26:42.644259514Z: DEBUG
plugins.OnRequest calling 0 plugins
ERROR: api.go:209: 2020-09-15T23:26:42.651463829Z: 172.20.0.1:47534 dsr
assignment querying existing: sql: no rows in result set
DEBUG: api.go:214: 2020-09-15T23:26:42.651514639Z: Internal Server Error
172.20.0.1:47534 - admin [15/Sep/2020:23:26:42 +0000] "PUT
/api/2.0/deliveryservice_requests/1/assign? HTTP/1.1" 500 83 7
"python-requests/2.22.0" 2703160290 NON_IMS
INFO: routing.go:252: 2020-09-15T23:26:42.652031369Z: PUT
/api/2.0/deliveryservice_requests/1/assign? handled (reqid 33624) in 7.774269ms
```
which suggests that a `database/sql.ErrNoRows` isn't being handled somewhere.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]