I'm following DeserializeErrorBody.java as a guide
When I use Converter<ResponseBody, Error> errorConverter, Error being a POJO class for my errors, I would get an EOFException trying to do errorConverter.convert(response.errorBody()); with the log being:java.io.EOFException: End of input at line 1 column 1 path$...
If I were to log erroBody.string() it would print the error that the server sends {"message":"Incorrect user or password"}
Moreover the error code at response.code() is 401 and the response.body() is null
Why do I get this error if the body is not null?
I was using Observable<ResponseBody> for the Retrofit interface, like I would use Call<ResponseBody> to check only response.isSuccessful().
Turns out I need to use Observable<Response<Void>> to skip the deserialization of an empty body which causes the EOFException.
Related
I'm trying to send int response but get an error but when I use both as a string then response get successfully.
post("/employee") {
call.respond(mapOf("hey" to "Hey","if" to 1))
}
LOGCAT
java.lang.IllegalStateException: Serializing collections of different element types is not yet supported. Selected serializers: [kotlin.String, kotlin.Int]
at io.ktor.serialization.kotlinx.SerializerLookupKt.elementSerializer(SerializerLookup.kt:45)
at io.ktor.serialization.kotlinx.SerializerLookupKt.guessSerializer(SerializerLookup.kt:29)
at io.ktor.serialization.kotlinx.KotlinxSerializationBase.serialize$ktor_serialization_kotlinx(KotlinxSerializationBase.kt:34)
at
You can't pass different types in response "yet" like mentioned in stacktrace. As a workaround you can pass 1 as string or create custom class for this response and serialize it to json and send it like that
I'm using the NestJS #FilesInterceptor to parse an array of files in a multipart request, here's how I use it:
#FilesInterceptor('files', 3, { some other options })
I need a specific error to be thrown if more than 3 files are sent, but what I get is a socket hangup client-side
Error: socket hang up
and this is the error logged in the console of the server:
Error: Unexpected end of multipart data
In the end: server crashed :(
So, how can I catch this error to handle it and prevent crashing?
It doesn't seem to be an instance of HttpException so the exception filter is not useful.
I could have done the length check in the controller, but I need { some other options }, so I must set a value for the maxCount
I found out the problem: the server has a global interceptor that implements a timeout for incoming requests. If I remove it, then the error is parsed correctly to an HttpException the client gets a BadRequest as expected
I'm still confused about why this doesn't work when I put it all together...
my requirement is to sent the error http status and error message in the body.
In Case of error in flow i need to pass the http code in the status field.
I can configure this http listner but don't know how to set this to get into payload. Please guide on that.
I'm expecting the MEL to get the 400 Bad Request
{
'status': "400 Bad Request",
'message': error.description
}
I could think of 2 ways of doing this:
1.You can use RAML and for every status code you can send appropriate responses as per your use case.This I think is the best way of doing it.
2.You can have the value for status and message key of your response body inside error handling block.Configure the 'TYPE' condition of your error handling block to catch a certain HTTP error message , then inside that you can set 2 vars: one with the status value and other with message value.Then use this vars in the Error response section of HTTP listener. You'll be ending up with many such error handling blocks if you want to address multiple status codes.
Let me know if you need further clarifications.Hope it helps.
Given have the following list of steps
Given path 'verify'
And header x-api-key = apiKey
And header tenant-id = tenantId
And request a_json_object_with_invalid_user_id_to_verify
When method put
Then status 404
When the endpoint returned HTTP 200 (which is a bug that i need to fix) but with an invalid json response such as
{
"score" :
}
This exception is thrown
com.jayway.jsonpath.InvalidJsonException: net.minidev.json.parser.ParseException: Unexpected character (}) at position 15.
at com.jayway.jsonpath.spi.json.JsonSmartJsonProvider.parse(JsonSmartJsonProvider.java:64)
at com.jayway.jsonpath.internal.JsonContext.parse(JsonContext.java:82)
at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:596)
at com.intuit.karate.JsonUtils.toJsonDoc(JsonUtils.java:84)
at com.intuit.karate.StepDefs.method(StepDefs.java:344)
I expect to see the test failed because of wrong status code 200 received of the expected 404. I would like to know if throwing this exception is correct in karate?
Thanks.
I apologize for mis-reading your question.
There is indeed a bug in Karate when handling malformed JSON responses.
We have opened an issue, you should be able to get a patch version very soon: https://github.com/intuit/karate/issues/259
I am using the following code to send Error message.
This is my own error code and custom message. I am sending the message in response.
throw new WebApplicationException(
Response.status(1002)
.header(ae.getMessage(), ae)
.type(MediaType.TEXT_PLAIN)
.build());
The problem is, the front end guys are able to see the status code but not the message. Is there any other way to solve this issue?
You should use entity method to set message:
Response.status(1002)
.entity(ae.getMessage())
.type(MediaType.TEXT_PLAIN)
.build());