public void Delete(T entity) { try { if (entity == null) { throw new ArgumentNullException("entity"); } if (!this.Entities.Local.Contains(entity)) { this.Entities.Attach(entity); } this.Entities.Remove(entity); this._context.SaveChanges(); } catch (DbEntityValidationException dbEx) { var msg = string.Empty; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { msg += Environment.NewLine + string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } var fail = new OceanException(msg, dbEx); //Debug.WriteLine(fail.Message, fail); throw fail; } }
public Exception buildException(Stream istream, int statusCode, String charSet) { istream.Position = 0; DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(ErrorExceptionDesc)); object resultObj = jsonSerializer.ReadObject(istream); ErrorExceptionDesc result = (ErrorExceptionDesc)resultObj; String errorCodeStr = result.getError_code(); String errorMesage = result.getError_message(); OceanException oceanException = new OceanException(errorMesage); oceanException.setError_code(errorCodeStr); oceanException.setError_message(errorMesage); return(oceanException); }
/// <summary> /// Refreshs the refresh token. /// </summary> /// <param name="token">Token.</param> public virtual void RefreshRefreshToken(AccessToken token) { /* * { * "error_description": "refreshToken is too long to expire with expireTime 20191014003220000+0800", * "error": "invalid_request" * } */ try { SyncAPIClient client = new SyncAPIClient(token.App_Key, token.App_Secret); var newToken = client.refreshRefreshToken(token.Access_Token, token.Refresh_Token); token.Access_Token = newToken.getAccess_token(); token.Expires_In = newToken.getExpires_time(); token.Refresh_Token = newToken.getRefresh_token(); token.Refresh_Token_Timeout = TransformDateTime(newToken.getRefresh_token_timeout()); token.AliId = newToken.getAliId().ToString(); token.Resource_Owner = newToken.getResource_owner(); token.MemberId = newToken.getMemberId(); token.Status = (int)CallbackMessageStatus.Success; token.Comment = "Success. " + JsonConvert.SerializeObject(newToken); } catch (Exception err) { token.Status = (int)CallbackMessageStatus.Failed; token.Comment = err.ToString(); // Notice to admin // Error code : 200 string body = ""; try { OceanException oceanException = err as OceanException; body = @" Hi admin, There are some error when executte refresh 'Refresh-Token' background job. "; body += @" Error Code: " + oceanException.getError_code(); body += @" Error Message: " + oceanException.getError_message(); body += @" Detail: " + oceanException.ToString(); } finally { body += "\r\nError: " + err.ToString(); } // string body = @" //Hi admin, //There are some error when executte refresh 'Refresh-Token' background job. //"; // body += @" //Error Code: " + err.getError_code(); // body += @" //Error Message: " + err.getError_message(); // body += @" //Detail: " + err.ToString(); emailManager.SendMail("[XTOPMS] 刷新 RefreshToken 时出现异常 (Error 200)", body, false); } accessTokenRepository.Update(token); }