-
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.
Refactor exception handling for REST API.
Make `HasuraErrorExtensions` class hierarchy a sealed class hierarchy.
- Loading branch information
Showing
3 changed files
with
88 additions
and
94 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
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/fi/hsl/jore4/timetables/api/util/HasuraErrorExtensions.kt
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,38 @@ | ||
package fi.hsl.jore4.timetables.api.util | ||
|
||
import fi.hsl.jore4.timetables.enumerated.TimetablesPriority | ||
import org.springframework.http.HttpStatus | ||
import java.util.UUID | ||
|
||
sealed class HasuraErrorExtensions(httpStatus: HttpStatus) { | ||
// code must be 4xx | ||
val code: Int = httpStatus.value() | ||
} | ||
|
||
class PlainStatusExtensions(httpStatus: HttpStatus) : HasuraErrorExtensions(httpStatus) | ||
|
||
class InvalidTargetPriorityExtensions( | ||
httpStatus: HttpStatus, | ||
val targetPriority: TimetablesPriority | ||
) : HasuraErrorExtensions(httpStatus) | ||
|
||
class StagingVehicleScheduleFrameNotFoundExtensions( | ||
httpStatus: HttpStatus, | ||
val stagingVehicleScheduleFrameId: UUID | ||
) : HasuraErrorExtensions(httpStatus) | ||
|
||
class TargetVehicleScheduleFrameNotFoundExtensions( | ||
httpStatus: HttpStatus, | ||
val stagingVehicleScheduleFrameId: UUID | ||
) : HasuraErrorExtensions(httpStatus) | ||
|
||
class MultipleTargetFramesFoundExtensions( | ||
httpStatus: HttpStatus, | ||
val stagingVehicleScheduleFrameId: UUID, | ||
val targetVehicleScheduleFrameIds: List<UUID> | ||
) : HasuraErrorExtensions(httpStatus) | ||
|
||
class TargetPriorityParsingExtensions( | ||
httpStatus: HttpStatus, | ||
val targetPriority: Int | ||
) : HasuraErrorExtensions(httpStatus) |
6 changes: 1 addition & 5 deletions
6
src/main/kotlin/fi/hsl/jore4/timetables/api/util/HasuraErrorResponse.kt
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 |
---|---|---|
@@ -1,13 +1,9 @@ | ||
package fi.hsl.jore4.timetables.api.util | ||
|
||
// See https://hasura.io/docs/latest/actions/action-handlers/#returning-an-error-response | ||
open class HasuraErrorResponse( | ||
class HasuraErrorResponse( | ||
nullableMessage: String?, | ||
val extensions: HasuraErrorExtensions | ||
) { | ||
val message = nullableMessage ?: "An error occurred." | ||
} | ||
|
||
open class HasuraErrorExtensions( | ||
open val code: Int // Must be a 4xx code | ||
) |