Closed umbertix closed 6 years ago
problem solved on 1.0.0-rc.7
:smile:
I try with included demo, and work fine. The code
this.booksService.get(id)
.toPromise()
.then((book) => {
book.attributes.title = book.attributes.title + 'x';
return book.save();
})
.then((response) => {
console.log('all good', response);
})
.catch((error) => {
console.error('err :/', error);
});
Work fine for me.
Can you post data returned of server? On my case is:
{
"data": {
"type": "books",
"id": "7",
"attributes": {
"title": "Ledner-Stehrx",
"date_published": "1979-11-10",
"isbn": null
},
"relationships": {
"author": {
"data": {
"type": "authors",
"id": "29"
}
},
"chapters": {
"data": []
},
"photos": {
"data": [
{
"type": "photos",
"id": "157"
}
]
},
"serie": {
"data": {
"type": "series",
"id": "49"
}
},
"stores": {
"data": [
{
"type": "stores",
"id": "26"
}
]
}
},
"links": {
"self": "/v2/books/7"
}
}
}
I think that I got what is actually going on. My response is a 202
, I believe that this is causing the problem since is not the expected 201
. I'll try update it in the following days, but most likely is my side of the implementation so we can close this issue. The element is sent correctly. :)
@umbertix the library has no difference betwen 201 and 202. Please check and post for help. Thanks for your collaboration
Ok.. So the actual request is succesfull and the data updates. So is partially correct. But by using this code for example
this._categoryService.get(categoryId)
.toPromise()
.then((category) => {
category.attributes.name = this.form.get('name').value;
category.attributes.description = this.form.get('description').value;
return category.save();
})
.then(() => {
swal('Congratulations!', 'The ingredient has been added!', 'success');
})
.catch((error) => {
console.log(error);
swal('Oops!', 'Something went wrong!', 'error');
});
I always stomp on the catch, rather than actually resolving the .then
. And I get an error in console
@umbertix, some ideas...
relationships.ingredients.data
and relationships.products.data
are not arrays, then I think service marked hasMany: false
right?If the problem persists, Can you show me lines where you get the error? I cant follow lines on chuncked code :(. A response on plain text will be better.
If your server is online, maybe you can share a CURL....
1.0.0-rc.7
which I believe is the latest version.The lines where I get the error is exactly the one that I pasted. If u add me on skype I can send you the curl/url privately
Btw I just found out the a similar behaviour happens with the creating of new elements. Might it be something on the promises?
[UPDATE] Ok, I think that i've narrowed down the problem due to my JSONAPI response. I'm not returning the information in the data attribute but in the meta. Because of that when u try to access the id attribute inside data o anythin else it just fails. I'll try find that bit of code and add a condition arround it so at least does not spit out an error.
@umbertix, on 1.0.0-rc.8
we set with default values when server data id, attributes or relationships are not defined.
Please, if the problem persists, post text of your code and server response.
Hi I've tried to update one of my reults following the example but does not seem to be liking it.
I've tried with this code:
But i keep recieving the error attached. Also tried with
.subscribe
but I've got a similar result. I've tried checking the demo site but can't it to work.