Skip to content

Commit

Permalink
Merge pull request #9 from kw-notice/refactor/issue-8
Browse files Browse the repository at this point in the history
fix : fix alarm controller
  • Loading branch information
Tianea2160 authored Feb 11, 2023
2 parents 6eaa28d + 16646fb commit b411ab3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 32 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.knet.dormitory.web.alarm.dto

import com.knet.dormitory.domain.alarm.AlarmTopic
import jakarta.validation.constraints.NotNull

class SendMessageRequest(
@field:NotNull(message = "title is null")
val title: String? = null,
@field:NotNull(message = "body is null")
val body: String? = null,
@field:NotNull(message = "topic is null")
val topic: AlarmTopic? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.knet.dormitory.web.shared.exception

import com.knet.dormitory.web.shared.dto.ErrorResponse
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.MethodArgumentNotValidException
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RestControllerAdvice

@RestControllerAdvice
class GlobalExceptionHandler {

@ExceptionHandler(MethodArgumentNotValidException::class)
fun methodArgumentNotValidException(
exception: MethodArgumentNotValidException
): ResponseEntity<ErrorResponse> = ResponseEntity
.status(HttpStatus.BAD_REQUEST)
.body(
ErrorResponse(
status = HttpStatus.BAD_REQUEST,
message = exception.bindingResult.allErrors[0].defaultMessage ?: ""
)
)

@ExceptionHandler(IllegalArgumentException::class)
fun illegalArgumentException(
exception: IllegalArgumentException
): ResponseEntity<ErrorResponse> = ResponseEntity
.status(HttpStatus.BAD_REQUEST)
.body(
ErrorResponse(
status = HttpStatus.BAD_REQUEST,
message = exception.message ?: ""
)
)
}

0 comments on commit b411ab3

Please sign in to comment.