georgehob Posted February 22, 2017 Report Share Posted February 22, 2017 Hi, We've been using the Javascript API for a while to allow users to create a project and tasks associated with it. All good for most submissions, but we do get fairly frequent errors that seem to have to do with task creation failures. This is what the task creation call looks like: function createTask(task, project) { var taskObj = { context_type: "task", name: task, parent_id: project.id, project: project, object_type_id: "11c137c0-ee7e-4f9c-91c5-8c77cec22b2c", bid: 0, priority_id: $scope.selectedPriority.priority_id, status_id: "29c8fb88-62c2-11e5-a7f9-42010af0e994", type_id: "ae1e2480-f24e-11e2-bd1f-f23c91dfaa16" } return session.create("Task", taskObj); } The number of tasks created per user request doesn't seem to matter as far as when the errors occur, there have been failures with anywhere from 1-10+ task creations per user request (task creation requests are also spaced out by 500ms, which should be plenty). Cannot find any consistent patterns as far as what might be causing the failures. The other major problem with this is it looks like the whole api crashes when a session.create call fails, which makes it impossible to catch the errors. Tried try/catching and other things, no luck. This makes it hard to figure out if it's a problem on our end or on ftrack's... Any thoughts on this appreciated! Would like to know if this is a problem that's appeared before for anyone else, too, as well as if there is a way to catch these errors and log them or something before the whole thing crashes. Link to comment Share on other sites More sharing options...
Lucas Correia Posted February 22, 2017 Report Share Posted February 22, 2017 Hi, I don't see anything immediately wrong with the code, though there might be something I am missing. Some thoughts: * name must be unique for a parent_id (Two tasks within a folder can not have the same name) * All relationships must point to existing objects (parent_id, status_id, priority_id, type_id). * I am not sure if you have to set context_type and object_type_id, but that might be true. If you are able to capture a failed request body and response it would be helpful in order for us to troubleshoot this. Feel free to send it to support@ftrack.com if you don't want to post this here. Link to comment Share on other sites More sharing options...
georgehob Posted February 22, 2017 Author Report Share Posted February 22, 2017 Hi Lucas, Thanks for the reply. Task names should not be a problem, they are always unique per project, and we have seen failures with just one task created on a project. The objects referenced (parent, parent_id, status etc) *should* always defined, as they are queried beforehand. As far as capturing the failed request body, we are having difficulty doing so as I mentioned in my post. I have tried try/catching the whole task creation function with no luck. Also tried logging in .then(), .fail(), .finally() of the session.create call but the code does not get there if the create call fails. If I'm in the browser and there happens to be an error, I can see the (vague) log in the console, as well as a more detailed response in the Network section of the inspector...just can't seem to get there via code and record that. Is there something I'm missing as far as catching these failed requests, or do you have a suggested way of doing so? Link to comment Share on other sites More sharing options...
Lucas Correia Posted February 23, 2017 Report Share Posted February 23, 2017 The JavaScript API uses ES2015 Promises, which have a `then` and a`catch` method, but no fail or finally methods. To log the request and failure, you can use the following: var taskObj = {...}; console.info('Creating task using data', taskObj); var createRequest = session.create('Task', taskObj); createRequest.catch(function (error) { console.error('Failed to create task', error); }); return createRequest; Regards, Lucas Link to comment Share on other sites More sharing options...
georgehob Posted February 23, 2017 Author Report Share Posted February 23, 2017 Wow, did not realize that's how you catch these things in promises. Thanks very much Lucas, gonna try this out and let you know the results. Link to comment Share on other sites More sharing options...
georgehob Posted February 23, 2017 Author Report Share Posted February 23, 2017 Ok, just tried it out, .catch does grab the error before everything crashes, but It's not what I was expecting. The error always comes back as this: TypeError: b.ServerError is not a constructor at ftrack.min.js:10 which is the vague error I referred to earlier that would appear in the console. This doesn't help us get to the root of the issues we're seeing. The errors in the network log are more along the lines of " Cannot add or update a child row: a foreign key constraint fails", which is much more helpful but I cannot capture and log these errors (tried Angular http interceptors and other things with no luck). It would be great if the error logging in the ftrack js could log these along with (or instead of) the b.ServerError message. Is there another way to record these network errors? Link to comment Share on other sites More sharing options...
Lucas Correia Posted February 24, 2017 Report Share Posted February 24, 2017 The TypeError is not expected, you should have a receive a ServerError with the message. Are you running a version of the API that you have built or a pre-bundled version you received from us? Email us a t support@ftrack.com if you need a new version. I just tried using the latest version of the JavaScript API, and get the error message as a ServerError. I verified this using the following code: function logResponse(response) { console.info('Success', response); } function logError(error) { console.error('Failed to create task', error); } function testCreateTask(priorityId) { var TEST_PROEJCT = '0cd8f638-f847-11e6-8d73-3c0754289fd3'; var TASK_OBJECT_TYPE_ID = '11c137c0-ee7e-4f9c-91c5-8c77cec22b2c'; var data = { name: 'test-task-' + Date.now(), parent_id: TEST_PROEJCT, project_id: TEST_PROEJCT, object_type_id: TASK_OBJECT_TYPE_ID, priority_id: priorityId, context_type: 'task', } session.create('Task', data).then(logResponse, logError); } Running the function testCreateTask with a bad priority will result in the a ServerError with the message "IntegrityError: [...] foreign key constraint fails", while running it without a priority will result in a successful creation (It will default to the first priority). To fix the issue, make sure all relationships (parent, project, status, type) have a value corresponding to an existing entity. Regards, Lucas Link to comment Share on other sites More sharing options...
georgehob Posted February 24, 2017 Author Report Share Posted February 24, 2017 Grabbed the latest version, it does give the ServerError messages now. This is what we needed, thanks Lucas! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.