-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: on license request errors, return response body as cause (#137)
This adds a new cause property to the error object returned by player.error() when a license request fails with a 4xx or 5xx status code. It's a string representation, so, if it's JSON a consumer would need to call JSON.parse manually as we can't know whether it's JSON or not.
- Loading branch information
Showing
6 changed files
with
78 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import videojs from 'video.js'; | ||
|
||
let httpResponseHandler = videojs.xhr.httpHandler; | ||
|
||
// to make sure this doesn't break with older versions of Video.js, | ||
// do a super simple wrapper instead | ||
if (!httpResponseHandler) { | ||
httpResponseHandler = (callback, decodeResponseBody) => (err, response, responseBody) => { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
|
||
// if the HTTP status code is 4xx or 5xx, the request also failed | ||
if (response.statusCode >= 400 && response.statusCode <= 599) { | ||
let cause = responseBody; | ||
|
||
if (decodeResponseBody) { | ||
cause = String.fromCharCode.apply(null, new Uint8Array(responseBody)); | ||
} | ||
|
||
callback({cause}); | ||
return; | ||
} | ||
|
||
// otherwise, request succeeded | ||
callback(null, responseBody); | ||
}; | ||
} | ||
export { httpResponseHandler }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters