Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
Tournament API
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kata
Tournament API
Commits
5c423d47
Commit
5c423d47
authored
3 months ago
by
Clément CORNU
Browse files
Options
Downloads
Patches
Plain Diff
feat: better exception handling
parent
97346e96
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/kotlin/configuration/ExceptionConfiguration.kt
+23
-8
23 additions, 8 deletions
src/main/kotlin/configuration/ExceptionConfiguration.kt
src/main/kotlin/configuration/SecurityConfiguration.kt
+0
-7
0 additions, 7 deletions
src/main/kotlin/configuration/SecurityConfiguration.kt
with
23 additions
and
15 deletions
src/main/kotlin/configuration/ExceptionConfiguration.kt
+
23
−
8
View file @
5c423d47
...
...
@@ -6,25 +6,40 @@ import io.ktor.server.application.*
import
io.ktor.server.plugins.*
import
io.ktor.server.plugins.statuspages.*
import
io.ktor.server.response.*
import
kotlinx.serialization.Serializable
import
software.amazon.awssdk.services.dynamodb.model.DynamoDbException
private
const
val
SOMETHING_WENT_WRONG
=
"Something went wrong"
private
const
val
RESOURCE_NOT_FOUND
=
"Resource not found"
@Serializable
data class
ErrorResponse
(
val
message
:
String
,
val
statusCode
:
Int
,
)
fun
Application
.
configureExceptionHandling
()
{
install
(
StatusPages
)
{
exception
<
Throwable
>
{
call
,
cause
->
when
(
cause
)
{
is
NotFoundException
->
call
.
respond
(
HttpStatusCode
.
NotFound
,
cause
.
message
?:
SOMETHING_WENT_WRONG
)
is
DynamoDbException
->
call
.
respond
(
HttpStatusCode
.
InternalServerError
,
cause
.
message
?:
"$SOMETHING_WENT_WRONG with DynamoDb"
val
(
errorStatusCode
,
errorResponse
)
=
when
(
cause
)
{
is
NotFoundException
->
HttpStatusCode
.
NotFound
to
ErrorResponse
(
message
=
cause
.
message
?:
RESOURCE_NOT_FOUND
,
statusCode
=
HttpStatusCode
.
NotFound
.
value
)
is
DynamoDbException
->
HttpStatusCode
.
ServiceUnavailable
to
ErrorResponse
(
message
=
cause
.
message
?:
"$SOMETHING_WENT_WRONG with DynamoDb"
,
statusCode
=
HttpStatusCode
.
ServiceUnavailable
.
value
,
)
is
AlreadyExistingPlayerException
->
call
.
r
espon
d
(
HttpStatusCode
.
BadRequest
,
cause
.
message
?:
SOMETHING_WENT_WRONG
is
AlreadyExistingPlayerException
->
HttpStatusCode
.
BadRequest
to
ErrorR
espon
se
(
message
=
cause
.
message
?:
SOMETHING_WENT_WRONG
,
statusCode
=
HttpStatusCode
.
BadRequest
.
value
,
)
else
->
throw
cause
}
call
.
respond
(
errorStatusCode
,
errorResponse
)
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/main/kotlin/configuration/SecurityConfiguration.kt
deleted
100644 → 0
+
0
−
7
View file @
97346e96
package
betclic.test.configuration
import
io.ktor.server.application.*
fun
Application
.
configureSecurity
()
{
//TODO Add comment to say what I would do in term of security
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment