Commit e66ea68e5dd2cf4bc642f640a0af9b4b399656db
1 parent
eec6b3d2
added exception handling code
Showing
2 changed files
with
65 additions
and
20 deletions
400-SOURCECODE/AIAHTML5.API/Controllers/ClientController.cs
@@ -7,6 +7,9 @@ using System.Net.Http; | @@ -7,6 +7,9 @@ using System.Net.Http; | ||
7 | using System.Web.Http; | 7 | using System.Web.Http; |
8 | using AIAHTML5.API.Models; | 8 | using AIAHTML5.API.Models; |
9 | using Newtonsoft.Json.Linq; | 9 | using Newtonsoft.Json.Linq; |
10 | +using System.Data.SqlClient; | ||
11 | +using System.Collections; | ||
12 | +using log4net; | ||
10 | 13 | ||
11 | namespace AIAHTML5.API.Controllers | 14 | namespace AIAHTML5.API.Controllers |
12 | { | 15 | { |
@@ -27,31 +30,60 @@ namespace AIAHTML5.API.Controllers | @@ -27,31 +30,60 @@ namespace AIAHTML5.API.Controllers | ||
27 | // POST api/client | 30 | // POST api/client |
28 | public HttpResponseMessage Post([FromBody]JObject siteUrl) | 31 | public HttpResponseMessage Post([FromBody]JObject siteUrl) |
29 | { | 32 | { |
30 | - HttpResponseMessage response = null; | 33 | + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); |
34 | + logger.Debug("inside POST in ClientController"); | ||
31 | 35 | ||
32 | - int siteId = AIAHTML5.API.Models.Users.ValidateLicenseSiteIP(siteUrl["siteIP"].ToString(), siteUrl["remoteIPAddress"].ToString(), siteUrl["accountNumber"].ToString(), Convert.ToByte(siteUrl["edition"].ToString())); | ||
33 | - if (siteId > 0) | 36 | + HttpResponseMessage response = null; |
37 | + try | ||
34 | { | 38 | { |
35 | - dynamic uerinfo = AIAHTML5.API.Models.Users.ValidateSiteLogin(siteUrl["siteIP"].ToString(), siteUrl["accountNumber"].ToString(), siteUrl["urlReferer"].ToString(), siteUrl["edition"].ToString(), siteId); | ||
36 | - if (uerinfo != null) | ||
37 | - response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(uerinfo) }; | 39 | + int siteId = AIAHTML5.API.Models.Users.ValidateLicenseSiteIP(siteUrl["siteIP"].ToString(), siteUrl["remoteIPAddress"].ToString(), siteUrl["accountNumber"].ToString(), Convert.ToByte(siteUrl["edition"].ToString())); |
40 | + if (siteId > 0) | ||
41 | + { | ||
42 | + dynamic uerinfo = AIAHTML5.API.Models.Users.ValidateSiteLogin(siteUrl["siteIP"].ToString(), siteUrl["accountNumber"].ToString(), siteUrl["urlReferer"].ToString(), siteUrl["edition"].ToString(), siteId); | ||
43 | + if (uerinfo != null) | ||
44 | + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(uerinfo) }; | ||
45 | + else | ||
46 | + { | ||
47 | + //ser user = new User(); | ||
48 | + //user.LoginFailureCauseId = AIAConstants.INVALID_CLIENT; | ||
49 | + //dynamic userinfo = user; | ||
50 | + //response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userInfo) }; | ||
51 | + | ||
52 | + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.INVALID_CLIENT) }; | ||
53 | + } | ||
54 | + } | ||
38 | else | 55 | else |
39 | { | 56 | { |
40 | - //ser user = new User(); | ||
41 | - //user.LoginFailureCauseId = AIAConstants.INVALID_CLIENT; | ||
42 | - //dynamic userinfo = user; | ||
43 | - //response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(userInfo) }; | ||
44 | - | ||
45 | - response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.INVALID_CLIENT) }; | 57 | + response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.MSG_NOT_AUTHORIZE_SITE_USER) }; |
58 | + | ||
59 | + | ||
46 | } | 60 | } |
61 | + return response; | ||
47 | } | 62 | } |
48 | - else | 63 | + catch (SqlException e) |
49 | { | 64 | { |
50 | - response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.MSG_NOT_AUTHORIZE_SITE_USER) }; | ||
51 | 65 | ||
66 | + logger.Fatal("SqlException occured for siteUrl =" + siteUrl["siteIP"].ToString() + " and siteUrl= " + siteUrl["siteIP"].ToString() + " & accountNumber = " + siteUrl["accountNumber"].ToString() + " &edition = " + siteUrl["edition"].ToString() + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); | ||
67 | + | ||
68 | + ArrayList supportMailList = UserUtility.GetSupportMailList(); | ||
69 | + string mailSubject = AIAConstants.SQL_CONNECTION_ERROR_MAIL_SUBJECT; | ||
70 | + string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace; | ||
71 | + UserUtility.SendEmailForException(0, supportMailList, "", mailSubject, mailBody,true,siteUrl); | ||
72 | + | ||
73 | + return new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(AIAConstants.SQL_CONNECTION_ERROR) }; | ||
74 | + } | ||
75 | + catch (Exception e) | ||
76 | + { | ||
77 | + | ||
78 | + logger.Fatal("Exception occured for loginId =" + siteUrl["siteIP"].ToString() + " and siteUrl= " + siteUrl["siteIP"].ToString() + " & accountNumber = " + siteUrl["accountNumber"].ToString() + " &edition = " + siteUrl["edition"].ToString() + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); | ||
79 | + ArrayList supportMailList = UserUtility.GetSupportMailList(); | ||
80 | + string mailSubject = AIAConstants.EXCEPTION_IN_AIAHTML5_MAIL_SUBJECT; | ||
81 | + string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace; | ||
82 | + UserUtility.SendEmailForException(0, supportMailList, "", mailSubject, mailBody, true, siteUrl); | ||
83 | + | ||
84 | + return new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(AIAConstants.EXCEPTION_OCCURED) }; | ||
52 | 85 | ||
53 | } | 86 | } |
54 | - return response; | ||
55 | } | 87 | } |
56 | 88 | ||
57 | // PUT api/client/5 | 89 | // PUT api/client/5 |
400-SOURCECODE/AIAHTML5.API/Models/UserUtility.cs
@@ -16,6 +16,7 @@ using System.Configuration; | @@ -16,6 +16,7 @@ using System.Configuration; | ||
16 | using System.Collections; | 16 | using System.Collections; |
17 | using System.Data; | 17 | using System.Data; |
18 | using System.Reflection; | 18 | using System.Reflection; |
19 | +using Newtonsoft.Json.Linq; | ||
19 | 20 | ||
20 | namespace AIAHTML5.API.Models | 21 | namespace AIAHTML5.API.Models |
21 | { | 22 | { |
@@ -216,10 +217,10 @@ namespace AIAHTML5.API.Models | @@ -216,10 +217,10 @@ namespace AIAHTML5.API.Models | ||
216 | } | 217 | } |
217 | } | 218 | } |
218 | 219 | ||
219 | - public static bool SendEmailForException(int userid, ArrayList mailToList, string sender, string mailSubject = "", string mailBody = "") | 220 | + public static bool SendEmailForException(int userid, ArrayList mailToList, string sender, string mailSubject = "", string mailBody = "", bool isMailForClentSite=false, JObject info=null) |
220 | { | 221 | { |
221 | ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); | 222 | ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); |
222 | - logger.Debug("Inside SendEmail with userid =" + userid); | 223 | + // logger.Debug("Inside SendEmail with userid =" + userid); |
223 | 224 | ||
224 | try | 225 | try |
225 | { | 226 | { |
@@ -235,8 +236,14 @@ namespace AIAHTML5.API.Models | @@ -235,8 +236,14 @@ namespace AIAHTML5.API.Models | ||
235 | lstToAddress.Add(email); | 236 | lstToAddress.Add(email); |
236 | } | 237 | } |
237 | 238 | ||
238 | - emailMessage = "Unable to process request for userid: " + userid; | ||
239 | - | 239 | + if (isMailForClentSite && info!=null) |
240 | + { | ||
241 | + emailMessage = "Unable to process request for siteUrl =" + info["siteIP"].ToString() + " and siteIP= " + info["siteIP"].ToString() + " & accountNumber = " + info["accountNumber"].ToString() + " &edition = " + info["edition"].ToString() ; | ||
242 | + } | ||
243 | + else | ||
244 | + { | ||
245 | + emailMessage = "Unable to process request for userid: " + userid; | ||
246 | + } | ||
240 | 247 | ||
241 | 248 | ||
242 | if (string.IsNullOrEmpty(sender)) | 249 | if (string.IsNullOrEmpty(sender)) |
@@ -264,7 +271,13 @@ namespace AIAHTML5.API.Models | @@ -264,7 +271,13 @@ namespace AIAHTML5.API.Models | ||
264 | return true; | 271 | return true; |
265 | } | 272 | } |
266 | catch (Exception ex) | 273 | catch (Exception ex) |
267 | - { | 274 | + { |
275 | + if (isMailForClentSite){ | ||
276 | + logger.Fatal("exception in SendEmail for siteUrl =" + info["siteIP"].ToString()+ ". msg= " + ex.Message + ", stacktrace= " + ex.StackTrace); | ||
277 | + | ||
278 | + } | ||
279 | + | ||
280 | + else | ||
268 | logger.Fatal("exception in SendEmail for userid"+userid+ ". msg= " + ex.Message + ", stacktrace= " + ex.StackTrace); | 281 | logger.Fatal("exception in SendEmail for userid"+userid+ ". msg= " + ex.Message + ", stacktrace= " + ex.StackTrace); |
269 | return false; | 282 | return false; |
270 | } | 283 | } |