@@ -394,14 +394,14 @@ public IActionResult AddComment(AddCommentViewModel addcomment)
394394 {
395395 List < string > errors = new List < string > ( ) ;
396396
397- if ( ! dasBlogSettings . SiteConfiguration . EnableComments )
397+ if ( ! ModelState . IsValid )
398398 {
399- return BadRequest ( ) ;
399+ errors . Add ( "[Some of your entries are invalid]" ) ;
400400 }
401401
402- if ( ! ModelState . IsValid )
402+ if ( ! dasBlogSettings . SiteConfiguration . EnableComments )
403403 {
404- return Comment ( addcomment . TargetEntryId ) ;
404+ errors . Add ( "Comments are disabled on the site." ) ;
405405 }
406406
407407 // Optional in case of Captcha. Commenting the settings in the config file
@@ -430,9 +430,10 @@ public IActionResult AddComment(AddCommentViewModel addcomment)
430430 }
431431 }
432432
433- if ( errors . Count > 0 )
434- return CommentError ( addcomment , errors ) ;
435-
433+ if ( errors . Count > 0 )
434+ {
435+ return CommentError ( addcomment , errors ) ;
436+ }
436437
437438 addcomment . Content = dasBlogSettings . FilterHtml ( addcomment . Content ) ;
438439
@@ -447,32 +448,35 @@ public IActionResult AddComment(AddCommentViewModel addcomment)
447448
448449 if ( state == NBR . CommentSaveState . Failed )
449450 {
450- ModelState . AddModelError ( "" , "Comment failed" ) ;
451- return StatusCode ( 500 ) ;
451+ logger . LogError ( new EventDataItem ( EventCodes . CommentBlocked , null , "Failed to save comment: {0}" , commt . TargetTitle ) ) ;
452+ errors . Add ( "Failed to save comment." ) ;
452453 }
453454
454455 if ( state == NBR . CommentSaveState . SiteCommentsDisabled )
455456 {
456- ModelState . AddModelError ( "" , "Comments are closed for this post" ) ;
457- return StatusCode ( 403 ) ;
457+ logger . LogError ( new EventDataItem ( EventCodes . CommentBlocked , null , "Comments are closed for this post: {0}" , commt . TargetTitle ) ) ;
458+ errors . Add ( "Comments are closed for this post." ) ;
458459 }
459460
460461 if ( state == NBR . CommentSaveState . PostCommentsDisabled )
461462 {
462- ModelState . AddModelError ( "" , "Comment are currently disabled" ) ;
463- return StatusCode ( 403 ) ;
463+ logger . LogError ( new EventDataItem ( EventCodes . CommentBlocked , null , "Comment are currently disabled: {0}" , commt . TargetTitle ) ) ;
464+ errors . Add ( "Comment are currently disabled." ) ;
464465 }
465466
466467 if ( state == NBR . CommentSaveState . NotFound )
467468 {
468- ModelState . AddModelError ( "" , "Invalid Target Post Id" ) ;
469- return NotFound ( ) ;
469+ logger . LogError ( new EventDataItem ( EventCodes . CommentBlocked , null , "Invalid Post Id: {0}" , commt . TargetTitle ) ) ;
470+ errors . Add ( "Invalid Post Id." ) ;
470471 }
471472
472- logger . LogInformation ( new EventDataItem ( EventCodes . CommentAdded , null , "Comment created on: {0}" , commt . TargetTitle ) ) ;
473+ if ( errors . Count > 0 )
474+ {
475+ return CommentError ( addcomment , errors ) ;
476+ }
473477
478+ logger . LogInformation ( new EventDataItem ( EventCodes . CommentAdded , null , "Comment created on: {0}" , commt . TargetTitle ) ) ;
474479 BreakSiteCache ( ) ;
475-
476480 return Comment ( addcomment . TargetEntryId ) ;
477481 }
478482
0 commit comments