function(response)

Started by JohnZeman, November 11, 2017, 09:03:31 PM

Previous topic - Next topic

JohnZeman

I have a question for you JavaScript gurus. 
The code below works to move selected files to the specified folder but I get no response no matter whether the file is successfully moved or not. 
All that is returned is

{}

Any ideas?



IMWS.post('v1/files/move', {
     scope: 'files',
     idlist: IMatch.idlist.fileWindowSelection,
     replace: 'replaceifolder',
     targetpath: 'D:\\Mine\\Photos\\Keepers\\!Queue'
}).then(function(response) {
        resultInfo.text(JSON.stringify(response, null, 2));
     },
     function(error) {
        resultInfo.text(JSON.stringify(response, null, 2));
});

ubacher

There are a few functions now which do not return any response any more.
I don't think we have any examples of how to correctly check the proper execution - other than
the error catch.

Mario

#2
If the endpoint returns 200OK, everything is OK. Your then() branch is executed. All is well.

In case of an error, IMatch returns an HTTP error code <> 200 (like, 500) and extended error info in the response body.
You can access that data in your error branch.

There are still some old endpoints which return unnecessary response data for the "It worked" case. These are left-overs from the massive, massive task of designing and implementing a web service that implements the IMatch functionality. I did not get everything right the first time, sorry. I will refactor such left-overs out over the next releases. Always keep an eye on the release notes - I publish details about such changes there.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

JohnZeman

I never considered the possibility that some endpoints may not return a response, I was assuming I wasn't doing something right.

Ok then, I can live with this, thanks for the enlightenment guys. :)

Mario

There is always a response from the server - the standard HTTP response code.
If it is "200 OK" jQuery will call your then() branch. Whether or not the server returned additional data (payload) is irrelevant. Some requests do not require any additional data.
A "Move File" option  either succeeds or fails.  If it succeeds, 200 OK is all you need to know. In case of an error, additional data is needed and provided in the response.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

JohnZeman

Well then that takes me back to my original question, all I get for a response no matter whether it is successful or not is an empty set of curly brackets {}

Everything else works the way I want.
I have dynamic counts of the total files in the database, the currently selected file count, and the number of files currently assigned to the Flag Set collection.

Each of those counts are updated as soon as anything changes but all I get for response text when moving files is an empty set of curly brackets.

JohnZeman

I should add I know there is a response, just no text in the response.

As a side note I have verified the replaceifolder parameter works as it should now however if a file is not replaced during a move because the existing destination file is newer, then why doesn't it trigger an error response?

Mario

#7
As I said, when IMWS returns 200OK, there is no additional data in the response.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Mario

Quoteif a file is not replaced during a move because the existing destination file is newer, then why doesn't it trigger an error response?

The existing file is not replaced. This is not an error, this is what you demanded.
If you need information about existing files up-front, use one of the endpoints which allow you to retrieve all files in a folder (database) or file system folder and then perofrm whatever test/operation you need to perform.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

JohnZeman

Ok, I think I have it now.  Sometimes it just takes awhile to get things pounded through my thick skull.  :o

Thanks Mario. :)

Mario

Programming is 40% forgetting old stuff, 40% learning new stuff and 20% thinking/typing...  ;)
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

Quote from: Mario on November 13, 2017, 08:56:58 AM
Programming is 40% forgetting old stuff, 40% learning new stuff and 20% thinking/typing...  ;)
No nono, it's only 10% thinking/typing, because there's also 10% just hoping it works  8)

sinus

Quote from: Carlo Didier on November 13, 2017, 01:41:56 PM
Quote from: Mario on November 13, 2017, 08:56:58 AM
Programming is 40% forgetting old stuff, 40% learning new stuff and 20% thinking/typing...  ;)
No nono, it's only 10% thinking/typing, because there's also 10% just hoping it works  8)

And in my case 74.54819 % "stealing" from others.  ;D 8) :-[
Best wishes from Switzerland! :-)
Markus