Skip to content

Commit 3b98609

Browse files
committed
refactor(WatsonService): Replaced try catch with null check since error is not thrown if there is no
1 parent 807bf77 commit 3b98609

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/IBM.WatsonDeveloperCloud/Service/WatsonService.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,16 @@ protected WatsonService(string serviceName)
104104
}
105105
}
106106

107-
try
107+
ApiKey = Environment.GetEnvironmentVariable(ServiceName.ToUpper() + "_APIKEY");
108+
if (string.IsNullOrEmpty(ApiKey))
108109
{
109-
ApiKey = Environment.GetEnvironmentVariable(ServiceName.ToUpper() + "_APIKEY");
110-
}
111-
catch(Exception e)
112-
{
113-
throw new NullReferenceException(string.Format("{0}_APIKEY did not exist. Please add credentials with this key in ibm-credentials.env. Error: {1}", ServiceName.ToUpper(), e.Message));
110+
throw new NullReferenceException(string.Format("{0}_APIKEY did not exist. Please add credentials with this key in ibm-credentials.env.", ServiceName.ToUpper()));
114111
}
115112

116-
try
117-
{
118-
Endpoint = Environment.GetEnvironmentVariable(ServiceName.ToUpper() + "_URL");
119-
}
120-
catch(Exception e)
113+
Endpoint = Environment.GetEnvironmentVariable(ServiceName.ToUpper() + "_URL");
114+
if (string.IsNullOrEmpty(Endpoint))
121115
{
122-
throw new NullReferenceException(string.Format("{0}_URL did not exist. Please add url with this key in ibm-credentials.env. Error: {1}", ServiceName.ToUpper(), e.Message));
116+
throw new NullReferenceException(string.Format("{0}_URL did not exist. Please add url with this key in ibm-credentials.env.", ServiceName.ToUpper()));
123117
}
124118

125119
TokenOptions tokenOptions = new TokenOptions()

0 commit comments

Comments
 (0)