Skip to content

Commit ed77c7d

Browse files
irvinesundayMIchaelMainer
authored andcommitted
Updating EntityRequest.Base.template with code fix for response headers issue (#202)
* Updating template with response headers fix. * New changes will propagate the fix for having response headers and status codes in request objects when UpdateAsync method is called in entities * Adding the exception documentation in IEntityRequest.Base - Refactoring in EntityRequest.Base to include this if includeSendParams == true so that it shows in the async UpdateAsync() method.
1 parent 3eb5335 commit ed77c7d

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

Templates/CSharp/Base/EntityRequest.Base.template.tt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ public void AppendUpdateAsyncHeader(string entityName, string lowerCaseEntityNam
350350
{
351351
stringBuilder.Append(Environment.NewLine);
352352
stringBuilder.Append(" /// <param name=\"cancellationToken\">The <see cref=\"CancellationToken\"/> for the request.</param>");
353-
}
353+
stringBuilder.Append(Environment.NewLine);
354+
stringBuilder.Append(" /// <exception cref=\"ClientException\">Thrown when an object returned in a response is used for updating an object in Microsoft Graph.</exception>");
355+
}
354356

355357
stringBuilder.Append(Environment.NewLine);
356358
stringBuilder.AppendFormat(" /// <returns>The updated {0}.</returns>", entityName);
@@ -390,6 +392,32 @@ public string GetEntityUpdateAsyncMethod(OdcmClass odcmClass, bool initializeCol
390392
stringBuilder.AppendFormat(" public async System.Threading.Tasks.Task<{0}> UpdateAsync({0} {1}ToUpdate, CancellationToken cancellationToken)", entityName, lowerCaseEntityName);
391393
stringBuilder.Append(Environment.NewLine);
392394
stringBuilder.Append(" {");
395+
stringBuilder.Append(Environment.NewLine);
396+
stringBuilder.AppendFormat(" if ({0}ToUpdate.AdditionalData != null)", lowerCaseEntityName);
397+
stringBuilder.Append(Environment.NewLine);
398+
stringBuilder.Append(" {");
399+
stringBuilder.Append(Environment.NewLine);
400+
stringBuilder.AppendFormat(" if ({0}ToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) ||", lowerCaseEntityName);
401+
stringBuilder.Append(Environment.NewLine);
402+
stringBuilder.AppendFormat(" {0}ToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode))", lowerCaseEntityName);
403+
stringBuilder.Append(Environment.NewLine);
404+
stringBuilder.Append(" {");
405+
stringBuilder.Append(Environment.NewLine);
406+
stringBuilder.Append(" throw new ClientException(");
407+
stringBuilder.Append(Environment.NewLine);
408+
stringBuilder.Append(" new Error");
409+
stringBuilder.Append(Environment.NewLine);
410+
stringBuilder.Append(" {");
411+
stringBuilder.Append(Environment.NewLine);
412+
stringBuilder.Append(" Code = GeneratedErrorConstants.Codes.NotAllowed,");
413+
stringBuilder.Append(Environment.NewLine);
414+
stringBuilder.AppendFormat(" Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, {0}ToUpdate.GetType().Name)", lowerCaseEntityName);
415+
stringBuilder.Append(Environment.NewLine);
416+
stringBuilder.Append(" });");
417+
stringBuilder.Append(Environment.NewLine);
418+
stringBuilder.Append(" }");
419+
stringBuilder.Append(Environment.NewLine);
420+
stringBuilder.Append(" }");
393421
stringBuilder.Append(Environment.NewLine);
394422
stringBuilder.AppendFormat(" this.ContentType = \"{0}\";", templateWriter.jsonContentType);
395423
stringBuilder.Append(Environment.NewLine);

Templates/CSharp/Base/IEntityRequest.Base.template.tt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ public void AppendUpdateAsyncMethodHeader(string entityName, string lowerCaseEnt
274274
{
275275
stringBuilder.Append(Environment.NewLine);
276276
stringBuilder.Append(" /// <param name=\"cancellationToken\">The <see cref=\"CancellationToken\"/> for the request.</param>");
277-
}
277+
stringBuilder.Append(Environment.NewLine);
278+
stringBuilder.Append(" /// <exception cref=\"ClientException\">Thrown when an object returned in a response is used for updating an object in Microsoft Graph.</exception>");
279+
}
278280

279281
stringBuilder.Append(Environment.NewLine);
280282
stringBuilder.AppendFormat(" /// <returns>The updated {0}.</returns>", entityName);

0 commit comments

Comments
 (0)