-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
novru
authored and
novru
committed
May 17, 2024
1 parent
dfeb258
commit a610dc4
Showing
12 changed files
with
96 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Application.Exceptions; | ||
using Microsoft.AspNetCore.Diagnostics; | ||
|
||
namespace Api.GlobalException; | ||
|
||
public class GlobalExceptionHandler : IExceptionHandler | ||
{ | ||
public async ValueTask<bool> TryHandleAsync(HttpContext httpContext, Exception exception, CancellationToken cancellationToken) | ||
{ | ||
(int statusCode, string errorMessage) = exception switch | ||
{ | ||
InvalidRatingException => (StatusCodes.Status406NotAcceptable, "Rating must be between 1 and 5, Please provide correct number"), | ||
UserNotFoundException => (StatusCodes.Status404NotFound, "Cannot find user, check user credentials"), | ||
CourseNotFoundException => (StatusCodes.Status404NotFound, "Cannot find course, check course credentials"), | ||
_ => (500, "Error occured, Try again.") | ||
}; ; | ||
|
||
httpContext.Response.StatusCode = statusCode; | ||
await httpContext.Response.WriteAsJsonAsync(errorMessage); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Application.Exceptions; | ||
|
||
public class CourseNotFoundException : Exception | ||
{ | ||
public CourseNotFoundException():base() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Application.Exceptions; | ||
|
||
public class UserNotFoundException : Exception | ||
{ | ||
public UserNotFoundException(string? message) : base(message) | ||
{ | ||
} | ||
|
||
public UserNotFoundException(string? message, Exception? innerException) : base(message, innerException) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Application.Models.Requests; | ||
|
||
public class AddCourseToFavRequest | ||
{ | ||
public string CourseId { get; set; } | ||
public string UserId { get; set; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters