Thanks to visit codestin.com
Credit goes to Github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
package yakworks.rest

import org.apache.poi.xssf.usermodel.XSSFWorkbook
import org.springframework.http.HttpStatus

import gorm.tools.transaction.WithTrx
import grails.gorm.transactions.Rollback
import grails.testing.mixin.integration.Integration
import okhttp3.HttpUrl
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.Response
import spock.lang.Specification
import yakworks.rally.orgs.model.Contact
import yakworks.rally.orgs.model.Org
import yakworks.rally.tag.model.Tag
import yakworks.rest.client.OkHttpRestTrait

import static yakworks.etl.excel.ExcelUtils.getHeader

@Integration
class ExceptionHandlerRestApiSpec extends Specification implements OkHttpRestTrait, WithTrx {

Expand Down Expand Up @@ -64,4 +52,16 @@ class ExceptionHandlerRestApiSpec extends Specification implements OkHttpRestTra
body.code == "error.unexpected"
body.detail.contains('nested exception is Assertion failed')
}

void "request method not supported - login"() {
when:
Response resp = get("/api/oauth/token")
Map body = bodyToMap(resp)

then:
body
body.containsKey('ok')
!body.ok
body.code
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.springframework.dao.DataIntegrityViolationException
import org.springframework.http.converter.HttpMessageNotReadableException
import org.springframework.validation.Errors
import org.springframework.validation.ObjectError
import org.springframework.web.HttpRequestMethodNotSupportedException

import gorm.tools.repository.errors.EmptyErrors
import yakworks.api.ApiStatus
Expand Down Expand Up @@ -101,7 +102,8 @@ class ProblemHandler {
else if (e instanceof DataAccessException) {
return buildFromDataAccessException(e)
}
else if (e instanceof HttpMessageNotReadableException || e instanceof JsonException) {
else if (e instanceof HttpMessageNotReadableException || e instanceof JsonException
|| e instanceof HttpRequestMethodNotSupportedException) {
//this happens if request contains bad data / malformed json. we dont want to log stacktraces for these as they are expected
return DataProblem.of(e)
}
Expand Down