-
-
Save gregturn/403b5e34e2dce9de1d19 to your computer and use it in GitHub Desktop.
| rest({method: 'DELETE', path: item._links.gallery.href}) | |
| .done(function() { | |
| findLinkedItem(item).remove(); | |
| $('#images ul').append(createItemRow(item)); | |
| }); |
By default, if the request is completed and a response is received, the promise success handler will be invoked, network errors will trigger the error handler.
You can change this behavior based on the status code with the rest/interceptor/errorCode interceptor, by default >=400 are treated as errors, but you can configure it.
As an aside, it looks like your trying to perform an operation on a related resource, if the 'item' was returned with HAL, you can instead do something like:
item.clientFor('gallery')({ method: 'delete' });Using clientFor simply created a client for the href defined by the relationship. You can then invoke the client like any other. Templated hrefs will be expanded as well.
Thanks. For some reason, Spring Data REST stopped handling this delete operation, but I didn't realize it because the follow function, which moved the item in the DOM happened anyway. I'll try it out.
Ahh. Nice! Well, taken that, I think I found something perfect for my situation:
item.clientFor('gallery')({method: 'DELETE'})
.done(function(response) {
if (response.status.code >= 200 && response.status.code < 300) {
findLinkedItem(item).remove();
$('#images ul').append(createItemRow(item));
}
});
@scothis What is the proper way to make the done() clause ONLY kick in if the DELETE was successful? And perhaps add an otherwise() clause to log if the delete was NOT successful?