Skip to content

Error handling #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
234b9fa
Support for error in RESTConnector
mediumTaj Nov 14, 2017
93ebdc9
refactor alchemy language
mediumTaj Nov 14, 2017
10ff6b1
refactor conversation
mediumTaj Nov 14, 2017
24dc202
refactored discovery, parse object in delete response, add helper fun…
mediumTaj Nov 15, 2017
75cb23d
refactored document conversion, documented callback delegates
mediumTaj Nov 15, 2017
b76962b
refactor language translator
mediumTaj Nov 15, 2017
11fa18f
refactored NLC
mediumTaj Nov 15, 2017
ed80dd4
refactor NLU
mediumTaj Nov 15, 2017
78e4f8f
refactor personality insights
mediumTaj Nov 15, 2017
397bee7
WIP - refactoring stt
mediumTaj Nov 16, 2017
c660206
refactor speech to text, fix some tests
mediumTaj Nov 16, 2017
8a56bec
refactored text to speech
mediumTaj Nov 16, 2017
ca3c7bb
refactor tone analyzer
mediumTaj Nov 16, 2017
aeb3e64
fixed test log messages
mediumTaj Nov 16, 2017
7760f83
refactored Tradeoff Analytics
mediumTaj Nov 16, 2017
e80b534
Merge branch 'develop' into 265-error-handling
mediumTaj Nov 16, 2017
8428cc3
refactored visual recognition
mediumTaj Nov 16, 2017
2aa2bfb
ensure all examples are working, refactor version from example and te…
mediumTaj Nov 17, 2017
b622fe9
fix warnings, add example for callbacks
mediumTaj Nov 17, 2017
2b32ac2
log tests on success
mediumTaj Nov 17, 2017
9ae91cd
update main readme with callback and customdata documentation, incorr…
mediumTaj Nov 17, 2017
1d6cee7
Fixed callbacks
mediumTaj Nov 17, 2017
3c8ae13
updated readme
mediumTaj Nov 17, 2017
2451894
Merge branch '265-error-handling' of github.com:watson-developer-clou…
mediumTaj Nov 17, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Examples/ServiceExamples/Scripts/ExampleAlchemyDataNews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using IBM.Watson.DeveloperCloud.Logging;
using IBM.Watson.DeveloperCloud.Utilities;
using System.Collections;
using IBM.Watson.DeveloperCloud.Connection;

public class ExampleAlchemyDataNews : MonoBehaviour
{
Expand Down Expand Up @@ -49,7 +50,8 @@ private IEnumerator Examples()
queryFields.Add(Fields.EnrichedUrlRelationsRelationSubjectText, "Obama");
queryFields.Add(Fields.EnrichedUrlCleanedtitle, "Washington");
string[] returnFields = { Fields.EnrichedUrlEntities, Fields.EnrichedUrlKeywords };
if (!_alchemyAPI.GetNews(OnGetNews, returnFields, queryFields))

if (!_alchemyAPI.GetNews(OnGetNewsSuccess, OnFail, returnFields, queryFields))
Log.Debug("ExampleAlchemyDataNews.GetNews()", "Failed to get news!");

while (!_getNewsTested)
Expand All @@ -58,9 +60,14 @@ private IEnumerator Examples()
Log.Debug("ExampleAlchemyDataNews.Examples()", "Alchemy data news examples complete!");
}

private void OnGetNews(NewsResponse newsData, string data)
private void OnGetNewsSuccess(NewsResponse resp, Dictionary<string, object> customData)
{
Log.Debug("ExampleAlchemyDataNews.OnGetNews()", "Alchemy data news - Get news Response: {0}", data);
_getNewsTested = true;
Log.Debug("ExampleAlchemyDataNews.OnSuccess()", "Response received: {0}", customData["json"].ToString());
}

private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
{
Log.Error("ExampleAlchemyDataNews.OnFail()", "Error received: {0}", error.ToString());
}
}
290 changes: 149 additions & 141 deletions Examples/ServiceExamples/Scripts/ExampleAlchemyLanguage.cs

Large diffs are not rendered by default.

98 changes: 98 additions & 0 deletions Examples/ServiceExamples/Scripts/ExampleCallback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Copyright 2015 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

using IBM.Watson.DeveloperCloud.Connection;
using IBM.Watson.DeveloperCloud.Logging;
using IBM.Watson.DeveloperCloud.Services.Conversation.v1;
using IBM.Watson.DeveloperCloud.Services.Discovery.v1;
using IBM.Watson.DeveloperCloud.Utilities;
using System.Collections.Generic;
using UnityEngine;

namespace IBM.Watson.DeveloperCloud.Examples
{
public class ExampleCallback : MonoBehaviour
{
private string _conversationUsername = "";
private string _conversationPassword = "";
private string _conversationUrl = "https://gateway.watsonplatform.net/conversation/api";
private string _workspaceId = "";

private string _discoveryUsername = "";
private string _discoveryPassword = "";
private string _discoveryUrl = "https://gateway.watsonplatform.net/discovery/api";

void Start()
{
LogSystem.InstallDefaultReactors();

// Create conversation instance
Credentials conversationCredentials = new Credentials(_conversationUsername, _conversationPassword, _conversationUrl);
Conversation conversation = new Conversation(conversationCredentials);
conversation.VersionDate = "2017-05-26";

// Create discovery instance
Credentials discoveryCredentials = new Credentials(_discoveryUsername, _discoveryPassword, _discoveryUrl);
Discovery discovery = new Discovery(discoveryCredentials);
discovery.VersionDate = "2016-12-01";

// Call with generic callbacks
conversation.Message(OnSuccess, OnFail, _workspaceId, "");
discovery.GetEnvironments(OnSuccess, OnFail);

// Call with sepcific callbacks
conversation.Message(OnMessage, OnMessageFail, _workspaceId, "");
discovery.GetEnvironments(OnGetEnvironments, OnGetEnvironmentsFail);
}

// Generic success callback
private void OnSuccess<T>(T resp, Dictionary<string, object> customData)
{
Log.Debug("ExampleCallback.OnSuccess()", "Response received: {0}", customData["json"].ToString());
}

// Generic fail callback
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
{
Log.Error("ExampleCallback.OnFail()", "Error received: {0}", error.ToString());
}

// OnMessage callback
private void OnMessage(object resp, Dictionary<string, object> customData)
{
Log.Debug("ExampleCallback.OnMessage()", "Response received: {0}", customData["json"].ToString());
}

// OnGetEnvironments callback
private void OnGetEnvironments(GetEnvironmentsResponse resp, Dictionary<string, object> customData)
{
Log.Debug("ExampleCallback.OnGetEnvironments()", "Response received: {0}", customData["json"].ToString());
}

// OnMessageFail callback
private void OnMessageFail(RESTConnector.Error error, Dictionary<string, object> customData)
{
Log.Error("ExampleCallback.OnMessageFail()", "Error received: {0}", error.ToString());
}

// OnGetEnvironmentsFail callback
private void OnGetEnvironmentsFail(RESTConnector.Error error, Dictionary<string, object> customData)
{
Log.Error("ExampleCallback.OnGetEnvironmentsFail()", "Error received: {0}", error.ToString());
}
}
}
13 changes: 13 additions & 0 deletions Examples/ServiceExamples/Scripts/ExampleCallback.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions Examples/ServiceExamples/Scripts/ExampleConversation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Collections;
using FullSerializer;
using System.Collections.Generic;
using IBM.Watson.DeveloperCloud.Connection;

public class ExampleConversation : MonoBehaviour
{
Expand Down Expand Up @@ -54,7 +55,7 @@ void Start()

private IEnumerator Examples()
{
if (!_conversation.Message(OnMessage, _workspaceId, "hello"))
if (!_conversation.Message(OnMessage, OnFail, _workspaceId, "hello"))
Log.Debug("ExampleConversation.Message()", "Failed to message!");

while (_waitingForResponse)
Expand Down Expand Up @@ -103,13 +104,13 @@ private void AskQuestion()
context = _context
};

if (!_conversation.Message(OnMessage, _workspaceId, messageRequest))
if (!_conversation.Message(OnMessage, OnFail, _workspaceId, messageRequest))
Log.Debug("ExampleConversation.AskQuestion()", "Failed to message!");
}

private void OnMessage(object resp, string data)
private void OnMessage(object resp, Dictionary<string, object> customData)
{
Log.Debug("ExampleConversation.OnMessage()", "Conversation: Message Response: {0}", data);
Log.Debug("ExampleConversation.OnMessage()", "Conversation: Message Response: {0}", customData["json"].ToString());

// Convert resp to fsdata
fsData fsdata = null;
Expand All @@ -134,4 +135,9 @@ private void OnMessage(object resp, string data)
Log.Debug("ExampleConversation.OnMessage()", "Failed to get context");
_waitingForResponse = false;
}

private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
{
Log.Error("ExampleConversation.OnFail()", "Error received: {0}", error.ToString());
}
}
Loading