I have this exception:
HttpException {#689 ▼
-statusCode: 403
-headers: []
#message: ""
#code: 0
#file: "/var/www/hqse/vendor/laravel/framework/src/Illuminate/Foundation/Application.php"
#line: 905
-trace: {▶}
}
I can not get the statusCode of the exception. I need to get "403".
The getCode() function returns 0.
Instead if I do:
$exc->statusCode
it returns an empty string.
In order to get statusCode there is method $exc->getStatusCode().
Related
In our use case, we need to reuse the same license for multiple sources for different videos, I came across the initializeMediaKeys function, but when called with the following emeOptions:
var emeOptions = {
keySystems : {
"com.widevine.alpha": {
url : myUrl,
audioRobustness: 'SW_SECURE_CRYPTO',
videoRobustness: 'SW_SECURE_CRYPTO'
}
}
}
I've tried several variations of this object as a parameter but I always get a:
instrument.js:109 VIDEOJS: ERROR: (CODE:5 MEDIA_ERR_ENCRYPTED) Unsupported keySystem or supportedConfigurations.
MediaError {code: 5, message: 'Unsupported keySystem or supportedConfigurations.'}
And opening the media error object I get:
MediaError {code: 5, message: 'Unsupported keySystem or supportedConfigurations.'}
code: 5
message: "Unsupported keySystem or supportedConfigurations."
responseContentType: "application/dash+xml"
responseStatus: 200
responseURL:[REDACTED]
token=[REDACTED]
[[Prototype]]: Object
MEDIA_ERR_ABORTED: 1
MEDIA_ERR_CUSTOM: 0
MEDIA_ERR_DECODE: 3
MEDIA_ERR_ENCRYPTED: 5
MEDIA_ERR_NETWORK: 2
MEDIA_ERR_SRC_NOT_SUPPORTED: 4
code: 0
message: ""
status: null
constructor: ƒ MediaError(value)
[[Prototype]]: Object
Could someone help me or give me a hint? Thanks.
It looks like a bug but asking the question just in case I have missed something.
Karate version is 1.1.0
The post request is as below. Note that content type is text/turtle and I use logPrettyResponse because further requests in test are testing RDF/XML and other serialisations.
* configure logPrettyResponse = true
Given path '/graph'
* text payload =
"""
<http://example.com/a7460f22-561a-4dde-922b-665bd9cf3bd9> <http://schema.org/description> "Test"#en.
"""
And request payload
And header Accept = 'text/turtle'
And header Content-Type = 'text/turtle'
When method POST
Then status 200
And I get below error
ERROR com.intuit.karate - org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 8; Element type "http:" must be followed by either attribute specifications, ">" or "/>"., http call failed
Reason this seems to be happening is that fromString method in JsValue.java is trying to parse turtle as XML because condition case '<' is true when response is turtle.
public static Object fromString(String raw, boolean jsonStrict, ResourceType resourceType) {
String trimmed = raw.trim();
if (trimmed.isEmpty()) {
return raw;
}
if (resourceType != null && resourceType.isBinary()) {
return raw;
}
switch (trimmed.charAt(0)) {
case '{':
case '[':
return jsonStrict ? JsonUtils.fromJsonStrict(raw) : JsonUtils.fromJson(raw);
case '<':
if (resourceType == null || resourceType.isXml()) {
return XmlUtils.toXmlDoc(raw);
} else {
return raw;
}
default:
return raw;
}
}
To solve the problem I have set logPrettyResponse to false. I would love to know if anyone has any other thoughts or if someone can confirm that it is a bug?
When i set lineLength to 200, which I would like to keep to not be limited, dart formatter is changing this:
throw RequestException(
message: responseData['message'],
statusCode: responseData['status'],
response: responseData['response']
);
to this:
throw RequestException(message: responseData['message'], statusCode: responseData['status'], response: responseData['response']);
How can I allow parameters on different lines? More generally, how can I force it to keep my multi-lines for any kind of statement?
try ending it with a ,
Like this:
throw RequestException(
message: responseData['message'],
statusCode: responseData['status'],
response: responseData['response'], // <- here
);
I'm trying to test my Quarkus application. I want to check that a response is greater than 0, the problem is that the endpoint I'm calling return a String and not a number. How can I convert the response to a number and check that it is greater than 0?
#Test
void getAdminListSize() {
given()
.when()
.header("Authorization", token_admin)
.get(PATH + "/get?listSize=true")
.then()
.statusCode(200)
.body(greaterThan(0))
;
}
This is the response I receive: "28357".
This is the error I get:
java.lang.AssertionError: 1 expectation failed.
Response body doesn't match expectation.
Expected: a value greater than <0>
Actual: 28357
Just extract the body to a variable and work with it
#Test
void getAdminListSize() {
String s = given()
.when()
.header("Authorization", token_admin)
.get(PATH + "/get?listSize=true")
.then()
.assertThat()
.statusCode(200)
.extract()
.body()
.asString();
convert s into a integer and do the assert
}
Other option is use .as(Clazz.class) and work with your dto if you have one
I am wondering how can I get the HTTP Status returned after a WebException was thrown. I am calling for example a RestAPI to get a token and the Server returns a 401 and a Body in json Format telling me that access is denied. I would like to get the 401 but have not found a way to only get 401.
Catch ex As WebException
Dim resp = New StreamReader(ex.Response.GetResponseStream()).ReadToEnd()
Dim errorNumber As Integer = CInt(ex.Status)
Console.WriteLine(ex.Message & " " & errorNumber)
Console.WriteLine(resp & " ")
Return resp
Below is the console output I have for my code:
CInt(ex.Status) = "7" and the
ex.message = "The remote server returned an error: (401) Unauthorized."
What I am looking for is to get the 401 or whatever the Server sends which would be equal to response.StatusCode
I actually found a way to access the 401 directly
Dim ExResponse = TryCast(ex.Response, HttpWebResponse)
Console.WriteLine(ExResponse.StatusCode)
I have the same problem and I realise a few things while I search for a solution.
WebExceptionStatus enum is not equivalent to http status code that the API you call returned. Instead it is a enum of possible error that may occour during a http call.
The WebExceptionStatus error code that will be returned when you receive an error (400 to 599) from your API is WebExceptionStatus.ProtocolError aka number 7 as int.
When you need to get the response body or the real http status code returned from the api, first you need to check if WebExceptionStatus.Status is WebExceptionStatus.ProtocolError. Then you can get the real response from WebExceptionStatus.Response and read its content.
This is a C# code but you folow the same logic in VB.Net
try
{
...
}
catch (WebException webException)
{
if (webException.Status == WebExceptionStatus.ProtocolError)
{
var httpResponse = (HttpWebResponse)webException.Response;
var responseText = "";
using (var content = new StreamReader(httpResponse.GetResponseStream()))
{
responseText = content.ReadToEnd(); // Get response body as text
}
int statusCode = (int)httpResponse.StatusCode; // Get the status code
}
// Handle other webException.Status errors
}