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

Object creation returns HTPP 200 instead of an HTTP 201 #65

Open
andacata opened this issue Jan 16, 2024 · 2 comments
Open

Object creation returns HTPP 200 instead of an HTTP 201 #65

andacata opened this issue Jan 16, 2024 · 2 comments
Labels
bug Something isn't working module: transport

Comments

@andacata
Copy link
Contributor

The OCPI documentation states that:

When the server receives a valid OCPI object it SHOULD respond with:
• HTTP 200 - Ok when the object already existed and has successfully been updated.
• HTTP 201 - Created when the object has been newly created in the server system.

But the HTTP code is generated based on the OCPI status, so it's difficult to know which HTTP status must be returned.

OcpiStatus.SUCCESS.code -> if (ocpiResponseBody.data != null) HttpStatus.OK else HttpStatus.NOT_FOUND

@lilgallon
Copy link
Member

I agress with you, there is a design issue here (#11 is also caused by this design issue). The real issue is that we do not have any context here.

In #11, we need something to say that even if we do not have any data, it should be HttpStatus.OK, and in your case, even if it's SUCCESS and there is some data, it has to be 201.

We need a way to pass the HttpStatus if we need something specific. And otherwise, we should use the existing logic. I am unsure what approach to use

Maybe

suspend fun <T> HttpRequest.httpResponse(fn: suspend () -> OcpiResponseBody<T>): HttpResponse =

should be changed to

suspend fun <T> HttpRequest.httpResponse(fn: suspend () -> Pair<OcpiResponseBody<T>, HttpStatus?>): HttpResponse =

In that case, we will need to update a lot of code.

Otherwise, one way to do that would be to use coroutine context, and pass HttpStatus if we want to override it. We will add support for adding stuff in a coroutine context soon

@lilgallon lilgallon added bug Something isn't working module: transport labels Jan 16, 2024
@andacata
Copy link
Contributor Author

👍

I'll try to think of other ways to avoid having to change too much code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module: transport
Projects
None yet
Development

No branches or pull requests

2 participants