What kind of issue is this?
I believe this library will benefit from having the Response object return an Enum on its method code(), like many other HTTP libraries and Frameworks do., so instead of:
if (response.code() == 200) {
// print "OK".
} else if (response.code() == 403) {
// print "Forbbiden"
}
In which we have to memorize all the HTTP codes, and maybe mix some, we can have:
if (response.code() == HttpStatus.OK_200) {
// print "OK".
} else if (response.code() == HttpStatus.Forbidden_403) {
// print "Forbbiden"
}
I think this will help the users to code quicker with the library (autocomplete can help with Enums) and beginners on REST and HTTP codes will be less prone to errors and mixing up what code does what.
The list of HTTP response codes are not finite and Java enums do not provide a mechanism for representing values that are not known at library compile time. If you are not comfortable with the raw code values, the isSuccessful() method will handle performing the appropriate range check.
This is similar to #2627 which suggested constants.
javax.ws.rs uses enums:
https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/Response.Status.html
So I thought Retrofit could follow the same idea.
Doing so can't be done until Retrofit 3 which we currently have no plans for any time soon. I still don't see a lot of provided value in an enum here.
I think the code becomes more readable, maybe you guys deal with HTTP codes for a long time and don't see the difference, but for beginners all those numbers on the middle of the logic can get a bit hard to read smoothly.
Just my $0.2
If ya want constants there are some here:
https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html
@swankjesse this looks interesting, thanks!
Most helpful comment
If ya want constants there are some here:
https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html