Return correct error from /images if unauthorized

We retry the request without "/images" suffix on 404 in
GetRepositoryData to see if the problem is lack of authorization, and if
it is, we return a 401 instead of a 404.

Fixes #7892.

Signed-off-by: Donald Huang <don.hcd@gmail.com>
Is res2 supposed to replace res at some point?  If the code does not error out then res is continued to be used.