sublinks / sublinks-api

MIT License
68 stars 17 forks source link

Invalid user return 400s rather than 404. #374

Closed lazyguru closed 2 months ago

lazyguru commented 2 months ago

It looks like we currently return an HTTP/400 error when a user is not found in an API call. Shouldn't this be a 404? (I could maybe see arguing for a 403, but 400 seems wrong here considering the only thing the client did "wrong" was asking for a user that doesn't exist).

api-1  | 2024-04-30T05:54:08.977Z DEBUG 1 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : GET "/api/v3/user?username=luke", parameters={masked}
api-1  | 2024-04-30T05:54:08.977Z DEBUG 1 --- [nio-8080-exec-4] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.sublinks.sublinksapi.api.lemmy.v3.user.controllers.UserController#show(GetPersonDetails)
api-1  | 2024-04-30T05:54:08.981Z DEBUG 1 --- [nio-8080-exec-4] .m.m.a.ExceptionHandlerExceptionResolver : Using @ExceptionHandler com.sublinks.sublinksapi.api.lemmy.v3.errorhandler.RestExceptionHandler#handleResponseStatusException(ResponseStatusException)
api-1  | 2024-04-30T05:54:08.982Z DEBUG 1 --- [nio-8080-exec-4] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [*/*] and supported [application/json, application/*+json]
api-1  | 2024-04-30T05:54:08.983Z DEBUG 1 --- [nio-8080-exec-4] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [com.sublinks.sublinksapi.api.lemmy.v3.errorhandler.ApiError@539d8f1c]
api-1  | 2024-04-30T05:54:08.984Z DEBUG 1 --- [nio-8080-exec-4] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.web.server.ResponseStatusException: 400 BAD_REQUEST "invalid_username_given"]
api-1  | 2024-04-30T05:54:08.986Z DEBUG 1 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Completed 400 BAD_REQUEST

NOTE: If we do fix this, we need to make sure @sublinks/sublinks-frontend-service is aware since they might need to update the seeder

rohit-satya commented 2 months ago

@lazyguru Please assign this issue to me

rohit-satya commented 2 months ago

@lazyguru @jgrim Please help with review