Skip to content

Commit

Permalink
Update error message
Browse files Browse the repository at this point in the history
  • Loading branch information
devdanielsun committed Feb 3, 2024
1 parent b3867b0 commit c050426
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions pollor.Server/Controllers/AnswersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public IActionResult GetAllAnswers()
.Include(a => a.Votes)
.ToList();
if (answers.IsNullOrEmpty()) {
return NotFound();
return NotFound(new { message = "No records found" });
}
return Ok(answers);
}
Expand All @@ -49,7 +49,7 @@ public IActionResult GetAnswerById(int id)
.Include(a => a.Votes)
.FirstOrDefault();
if (answer == null) {
return NotFound();
return NotFound(new { message = "No records found" });
}
return Ok(answer);
}
Expand All @@ -70,7 +70,7 @@ public IActionResult AddAnswer(AnswerModel answer)
context.SaveChanges();

if (newAnswer == null) {
return NotFound(newAnswer);
return NotFound(new { message = "No records found" });
}
return Created("answer/" + newAnswer.Entity.id.ToString(), newAnswer.Entity);
}
Expand Down
6 changes: 3 additions & 3 deletions pollor.Server/Controllers/PollsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public IActionResult GetAllPolls()
.ThenInclude(a => a.Votes)
.ToList();
if (polls.IsNullOrEmpty()) {
return NotFound();
return NotFound(new { message = "No records found" });
}
return Ok(polls);
}
Expand All @@ -52,7 +52,7 @@ public IActionResult GetPollById(int id)
.ThenInclude(a => a.Votes)
.FirstOrDefault();
if (poll == null) {
return NotFound();
return NotFound(new { message = "No records found" });
}
return Ok(poll);
}
Expand All @@ -73,7 +73,7 @@ public IActionResult AddPoll(PollModel poll)
context.SaveChanges();

if (newPoll == null) {
return NotFound(newPoll);
return NotFound(new { message = "No records found" });
}
return Created("poll/" + newPoll.Entity.id.ToString(), newPoll.Entity);
}
Expand Down
6 changes: 3 additions & 3 deletions pollor.Server/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public IActionResult GetAllUsers()
.ThenInclude(a => a.Votes)
.ToList();
if (users.IsNullOrEmpty()) {
return NotFound();
return NotFound(new { message = "No records found" });
}
return Ok(users);
}
Expand Down Expand Up @@ -76,7 +76,7 @@ public IActionResult GetCurrentUser()
.FirstOrDefault();
if (user == null)
{
return NotFound("User not found...");
return NotFound(new { message = "No records found" });
}
return Ok(user);
}
Expand All @@ -100,7 +100,7 @@ public IActionResult GetUserById(int id)
.ThenInclude(a => a.Votes)
.FirstOrDefault();
if (user == null) {
return NotFound();
return NotFound(new { message = "No records found" });
}
return Ok(user);
}
Expand Down
6 changes: 3 additions & 3 deletions pollor.Server/Controllers/VotesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public IActionResult GetAllVotes()
using (var context = new PollorDbContext()) {
List<VoteModel>? votes = context.Votes.ToList();
if (votes.IsNullOrEmpty()) {
return NotFound();
return NotFound(new { message = "No records found" });
}
return Ok(votes);
}
Expand All @@ -46,7 +46,7 @@ public IActionResult GetVoteById(int id)
.Where(v => v.id.Equals(id))
.FirstOrDefault();
if (vote == null) {
return NotFound();
return NotFound(new { message = "No records found" });
}
return Ok(vote);
}
Expand All @@ -67,7 +67,7 @@ public IActionResult AddVote(VoteModel vote)
context.SaveChanges();

if (newVote == null) {
return NotFound(newVote);
return NotFound(new { message = "No records found" });
}
return Created("vote/" + newVote.Entity.id.ToString(), newVote.Entity);
}
Expand Down
2 changes: 1 addition & 1 deletion pollor.client/src/app/polls/polls.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class PollsComponent {
this.pollsLoaded = true;
},
error: (err) => {
this.pollLoadingMsg = err.status + ' - ' + err.message;
this.pollLoadingMsg = err.status + ' - ' + err.error.message;
this.pollLoadingColor = "red";
console.error(err);
AlertMessage.addErrorAlert(err.error.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class UserProfileComponent {
this.userLoaded = true;
},
error: (err) => {
this.userLoadingMsg = err.status + ' - ' + err.message;
this.userLoadingMsg = err.status + ' - ' + err.error.message;
console.error(err);
AlertMessage.addErrorAlert(err.error.message);
},
Expand Down

0 comments on commit c050426

Please sign in to comment.