The response has been truncated in angular - json

The communication with the Api Rest server is fine, it returns code 200. The request used is GET, sending authentication parameters by the header. So far there, the problem is in the content of the response, it shows a partial json and an error message that says: The response has been truncated.
I used the same code with other methods and I had no problem. I infer that the problem is because the json that is returning is very large and truncates it.
public getTrialBalanceStatementPeriodwise(reportInput: TrialBalanceReportInput) {
reportInput.periodicReport=1;
return this.http.post('/TrueBooks/rest/reports/trialbalanceperiodwise', reportInput,{responseType:'json'});
}

Related

Request Body issue in Spring Boot PUT Request

I am trying to create a PUT request where admin will be making decision based on some criteria and Verifying or Rejecting a user. I expect this decision in JSON body(Refer to Verification method in below image). But I am confused what json body should I send. I have sent the following JSON body { "REJECTED" }
{ REJECTED }
REJECTED
But everytime, it is returning false in the above method. Please help!!
You are not returning any JSON here - your method type is void.
You need to return something maybe string or response itself.
Using System.out.println(), you are displaying the message on your console only but not sending a response to the server.

angular 4 http get request doesnt subscribe to json response (mongoose result) from api

the http client get request to the api, works I see that a json object is being returned with the command
res.send (data) after finding it in Mongoose.
I understand that httpclient now sends standard json format back from the api, however I don’t understand how to subbscribe to this data on the client side. How do I receive the object that is being send back with res.send.
I added an interface to the get request that sets up the variables that tie in with the json object.
However I can’t get the data nor do I get any failures as if the .subscribe is not being called.
I am using the httpclient docs but somehow I can’t get it to work.
Below the get request that I am using “might not be entirely correct” which works but the obj doesn’t get subscribed to
http.get(url, {params})
.subscribe (data => {console.log(data)});
}
ie. I get no error, which I expect as the log can’t read json format?

API endpoint returns text before and after the JSON content, causing parsing error

I'm using postman to test calling a rest service endpoint.
I'm trying to parse the JSON return content but it throws an error because the response body has more than just JSON.
This is how I parse it in my postman test script:
var jsonData = JSON.parse(responseBody);
Here is the response body:
--13398550-b6ea-4731-a8ee-4b2ad24c3cfe
Content-Type: application/json; charset=utf-8
//this is the actual content I want to parse --->
{"id":"123456","value":"the_value"}
--13398550-b6ea-4731-a8ee-4b2ad24c3cfe--
When I try to parse it, I get the following error (in postman)
There was an error in evaluating the test script: SyntaxError:
Unexpected number in JSON at position 3
Obviously because the content being parsed is not just JSON
Is this something special that the api is doing? Or am I just parsing it incorrectly?
NOTE: I'm not including details of the rest service function. If the cause of this issue is something that is being done by the service itself, then that is enough of an answer for me to perhaps ask another question or do some further investigation. The purpose of this question is to ask whether this is something special being done in HTTP, or if it's the service.
Edit:
I managed to see the server side code and it is indeed manually building the response with boundaries identified by a GUID. I'll have to manually parse the response
The server is not emitting straight up application/json, it's packed in a multipart mime envelope.
Whether or not it's doing that correctly depends on the response headers. If you didn't expect a multipart response, but a simple JSON response, then I'd say yes: it's something you need to fix server-side.

If my web application can't unmarshal client-supplied JSON, should I return 400 or 500?

I'm trying to use HTTP response codes properly but I'm a bit confused by which to return in this situation:
The body of a POST request from the client should contain a JSON representation of an object in my application. Assuming the body is non-empty and the content is JSON data, if json.Unmarshal returns an error (I'm programming in Go, but not that it matters), does that warrant 400 Bad Request or 500 Internal Server Error?
On one hand if it doesn't decode the data because the format is wrong, that's a bad request, but on the other hand it's a function returning an error on the server that means the operation can't proceed so it's an internal server error. In essence it's a 500 caused by a 400. So which should I be returning?

AFNetworking error parsing JSON

I'm using AFNetworking 2.3 API to fetch currency exchange rates which returns JSON. In addition to HTTP the API also supports HTTPS. I'm using a subclass of AFHTTPSessionManager and set the response serializer to AFJSONResponseSerializer.
If I use HTTP everything works as expected, however once I use HTTPS, I receive the following error
Error Domain=NSCocoaErrorDomain Code=3840 "The data couldn’t be read
because it isn’t in the correct format." (JSON text did not start with
array or object and option to allow fragments not set.)
UserInfo=0x60000046c700 {NSDebugDescription=JSON text did not start
with array or object and option to allow fragments not set.}
I checked the response data and it appears identical to the HTTP response. Also the response code is 200 and the header indicates
"Content-Type" = "application/json; charset=utf-8";
If I entry the url directly into safari the data appears as expected. I also tried setting the reading options of the response serializer to NSJSONReadingAllowFragments, but no change.
Is this a server side issue? What else could I do to debug this?