When i try to handling the response from server, I cant able to read the error status and detail (i.e., those fields are empty)
Below i show my response what i am getting,
{
"message": "Ember Data Request POST http://192.168.1.21:8888/api/test returned a 0?Payload (Empty Content-Type)?",
"name": "Error",
"errors":
[
{
"detail": "",
"status": "0",
"title": "The backend responded with an error",
}
],
"description":undefined,
"fileName":undefined
}
Why this fields are empty? what should i do to overcome this?
Related
Google API calling through postman.
Get url https://logging.googleapis.com/v2/projects/projectid/logs/
Error:
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"id\": Cannot bind query parameter. Field 'id' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"id\": Cannot bind query parameter. Field 'id' could not be found in request message."
}
]
}
]
}
}
In my django webapp, I have to pass user data param(udp) in a request and return the same in response without modifying it in view.
Request
{
"mobile": "111111111",
"udp":[
{
"key": "keyName",
"value":"valueName"
},
{
"key": "keyName",
"value":"valueName"
},
]
}
Response
{
"code": "200",
"message": "success message",
"response": {
"data":"user data"
"udp":[
{
"key": "keyName",
"value":"valueName"
},
{
"key": "keyName",
"value":"valueName"
}
]
}
}
I thought of acheiving this by writting custom middleware but after accessing request in middleware, View is throwing me error
you cannot access body after reading from request's data stream
Can anyone suggest how this can be implemented?
or
What will be best approach of doing this in django
I have a working Hyperledger-Fabric environment, running locally on my Mac. I setup the chaincode_example02 code, but the Query REST call isn't working. I trying doing a deploy and invoke and both of those calls work. I am using Postman to send the REST calls.
Query:
{
"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID": {
"name": "mycc",
"path": "/tmp/hyperledger-BR/example0/gopath/src/github.com/chaincode_example02/chaincode_example02"
},
"ctorMsg": {
"function": "query",
"args": ["b"]
}
},
"id": 0
}
Serverside Error:
Error starting Simple chaincode: Error handling message:
[ef980ad7-94c8-4ec9-92f4-3ebdd47e4321]Chaincode handler FSM cannot
handle message (RANGE_QUERY_STATE) with payload size (10) while in
state: ready
Postman Returned Error:
{ "jsonrpc": "2.0", "error": {
"code": -32003,
"message": "Query failure",
"data": "Error when querying chaincode: Error:Failed to execute transaction or query(Timeout expired while executing transaction)"
}, "id": 0 }
I have been digging online, but I have no idea why this is happening. Any clue as to why this is happening?
Using ember and ember-data 2.6 versions, I'm trying to get error handling working but running into issues. I'm using the RESTSerializer and I'm sending the following payload to my server:
{
"brand": {
"name": null,
"description": null,
}
}]
Since name cannot be null, this is what I'm sending back as my response:
{
"errors": [{
"code": null,
"detail": "may not be null",
"status": null,
"title": null,
"source": {
"pointer": "brand/name",
"parameter": null
}
}]
}
In my route, I am doing the following in the save promise on failure:
console.log(savedBrand.get('isValid')); // logs false
console.log(savedBrand.get('errors').toArray()); // logs [ ]
There doesn't seem to be a lot of detailed documentation on how this all works so I'm using this article as a starting point. I'm unsure as to why toArray() returns an empty array instead of my error that I'm returning in the JSON.
even though I'm not passing in the data per the json-api, the pointer still had to be set as if I were:
{
"errors": [{
"code": null,
"detail": "may not be null",
"status": null,
"title": null,
"source": {
"pointer": "/data/attributes/name",
"parameter": null
}
}]
}
I receive JSON Api conform errors from the backend:
{
"errors": [
{
"status": "400",
"source": {
"pointer": "/data/attributes/description"
},
"detail": "This field may not be null."
},
{
"status": "400",
"source": {
"pointer": "/data/attributes/due-date"
},
"detail": "This field may not be null."
},
{
"status": "400",
"source": {
"pointer": "/data/attributes/extra-comments"
},
"detail": "This field may not be null."
},
{
"status": "400",
"source": {
"pointer": "/data/attributes/name"
},
"detail": "This field may not be null."
},
{
"status": "400",
"source": {
"pointer": "/data/attributes/payment-type"
},
"detail": "This field may not be null."
},
{
"status": "400",
"source": {
"pointer": "/data/attributes/price"
},
"detail": "This field may not be null."
}
]
}
I try to show them in my template, as described in the EmberData documentation:
{{#each model.errors.messages as |message|}}
<div class="error">
{{message}}
</div>
{{/each}}
Nothing is shown. I would say the .errors in the model are not populated, but I am not sure how to check this. How can I:
display the received ajax reply?
make sure that EmberData is processing the reply and populating model.errors?
Show the processed model.errors in the console?
Show the model and all properties?
In general, I am experiencing that new versions of Ember are very hard to debug. Whenever I show any Ember object in the console, I just see some Computed properties which are not expanded whenever I try to peek into them.
My backend is:
Django 1.9
with django-rest-framework
django-rest-framework-json-api
EDIT
This is the data that I am POSTing to the backend (JSONAPi conform):
{
"data": {
"attributes": {
"name": null,
"description": null,
"extra-comments": null,
"min-price": 30,
"max-price": 3000,
"price-step": 10,
"price": null,
"payment-type": null,
"due-date": null
},
"relationships": {
"seller": {
"data": null
},
"artist": {
"data": null
},
"subcategory": {
"data": null
}
},
"type": "projects"
}
}
The backend is ok with this, detects the errors, and provides a JSON APi conform errors reply, as specified above.
I think I know what's happening (as it happened to me as well).
Change the HTTP error code from 400 to 422 (Unprocessable Entity) and check if it fixes the problem.
Also, looking at the source code for the JSONAPIAdapter (which extends from the RestAdapter) I think I'm right.
isInvalid: function(status, headers, payload) {
return status === 422;
},
This can be changed to (adapters/application.js):
import DS from 'ember-data';
import config from '../config/environment';
export default DS.JSONAPIAdapter.extend(DataAdapterMixin, {
host: config.API_HOST,
namespace: config.API_NAMESPACE,
isInvalid: function(status, headers, payload) {
return status === 400 || status === 422;
},
});
For reference, I have done this on the django side:
from rest_framework_json_api.exceptions import exception_handler
def custom_exception_handler(exc, context):
# DRF returns 400, but EmberData wants 422. I will force a 422, always.
# Call the rest_framework_json_api's exception handler first,
# to get the standard error response.
response = exception_handler(exc, context)
# TODO: is this correct? 422 in all exception cases?!
response.status_code = 422
return response