-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[hue] Error handling improvements #15460
Comments
Regardless of whether the response is valid JSON or an HTML error message, the payload is returned with HTTP 200 OK, so the ContentType is the only way to tell if something was wrong. |
@jlaur the Hue API documentation (e.g. see link below) gives all the error codes that might potentially be reported for each type of call i.e. 400, 401, 403, 404, 405, 429, 500, 503, 507 (maybe others too). In reality I only ever saw 401, 403 and of course 200.. https://developers.meethue.com/develop/hue-api-v2/api-reference/#resource_light__id__put |
This issue has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/philips-hue-clip-2-api-v2-discussion-thread/142111/239 |
OK, I didn't know that because the HTTP error code is not logged. 🙂 Anyway, it doesn't contradict what I wrote:
So my suggestion would be to check error code first and react appropriately on that. For 200 we would then move ahead and check
Thanks for the link. I briefly checked and they claim |
Yes. Although I think that strictly the HTML error is not an API error but rather a default fallback error of the bridge when the API is not running. If you open the HTML in a browser it displays a simple web page saying "sorry no lighting found" (something like that). You will also get the same error if you try (say) to open an API v2 page in your browser using something like this
|
@jlaur as you know from #15350 I am doing some work to improve the stability of |
@jlaur can I leave this one up to you? |
Yes. In the meantime I found the documentation: I'm currently looking into the implementation. This should work: offline.api2.comm-error.exception = An unexpected exception '{0}' occurred. when used like this: updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"@text/offline.api2.comm-error.exception [\"" + e.getMessage() + "\"]"); However, for some reason I'm seeing this in my tests: |
Okay, I found the issue. The position is not the problem, the surrounding apostrophes are. |
Small note - log from this morning:
This raises two questions:
I will try to add better logging for the "Error sending request" part in my own build to get more information the next time it happens. And also have a look at the code regarding reconnect logic. If any of this justifies a new issue (and/or PR), I will then create that as a result. Additional notes:
|
^ |
It did. |
Placeholder for some minor issues found.
Status description missing
This was observed in my logs:
When looking in the UI:
One issue seems to be a problem related to I18N. This works:
offline.api2.comm-error.exception = An unexpected exception occurred: {0}
This doesn't:
openhab-addons/bundles/org.openhab.binding.hue/src/main/resources/OH-INF/i18n/hue.properties
Line 235 in a293fc8
This doesn't work either:
It seems the placeholder variable needs to be at the end. Perhaps this feature is some kind of pure luck and is not designed to be used like this at all. I would need to investigate further.
Incomplete HTTP status code check
Another issue is here:
openhab-addons/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/connection/Clip2Bridge.java
Line 986 in 52c657f
This will usually happen when HTML content is returned. Most likely there is a HTTP status code that would be more interesting than the MIME type. However, only a few are explicitly handled, and the code is not returned:
openhab-addons/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/connection/Clip2Bridge.java
Lines 154 to 159 in 52c657f
I'm not sure what would be the best implementation for this, but a straight-forward one would be:
int httpStatus
toBaseStreamListenerAdapter
.int getHttpStatus()
for returning it.switch
statement above.putResource
and make sure to log it and also use the HTTP status rather than MIME type for determining if the call was successful. We can still check MIME type even for code 200 for being safe.The text was updated successfully, but these errors were encountered: