Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
minerva
core
Commits
f2b35173
Commit
f2b35173
authored
7 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
error reporting fixedd (proper json is sent to the client)
parent
d9654bd5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!195
Resolve "data overlay with miriam ids"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
rest-api/src/main/java/lcsb/mapviewer/api/BaseController.java
+14
-13
14 additions, 13 deletions
...-api/src/main/java/lcsb/mapviewer/api/BaseController.java
with
14 additions
and
13 deletions
rest-api/src/main/java/lcsb/mapviewer/api/BaseController.java
+
14
−
13
View file @
f2b35173
...
...
@@ -18,6 +18,7 @@ import com.fasterxml.jackson.core.JsonParseException;
import
com.fasterxml.jackson.databind.JsonMappingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.google.gson.Gson
;
import
lcsb.mapviewer.common.Configuration
;
import
lcsb.mapviewer.common.exception.InvalidStateException
;
...
...
@@ -30,30 +31,30 @@ public abstract class BaseController {
@ExceptionHandler
({
Exception
.
class
})
public
ResponseEntity
<
Object
>
handleException
(
Exception
e
,
WebRequest
request
)
{
if
(
e
instanceof
lcsb
.
mapviewer
.
services
.
SecurityException
)
{
return
new
ResponseEntity
<
Object
>(
"{\"error\" : \"Access denied.\",\"reason\":\""
+
e
.
getMessage
()
+
"\"}"
,
new
HttpHeaders
(),
HttpStatus
.
FORBIDDEN
);
return
createErrorResponse
(
"Access denied."
,
e
.
getMessage
(),
new
HttpHeaders
(),
HttpStatus
.
FORBIDDEN
);
}
else
if
(
e
instanceof
ObjectNotFoundException
)
{
return
new
ResponseEntity
<
Object
>(
"{\"error\" : \"Object not found.\",\"reason\":\""
+
e
.
getMessage
()
+
"\"}"
,
new
HttpHeaders
(),
HttpStatus
.
NOT_FOUND
);
return
createErrorResponse
(
"Object not found."
,
e
.
getMessage
(),
new
HttpHeaders
(),
HttpStatus
.
NOT_FOUND
);
}
else
if
(
e
instanceof
ObjectExistsException
)
{
return
new
ResponseEntity
<
Object
>(
"{\"error\" : \"Object already exists.\",\"reason\":\""
+
e
.
getMessage
()
+
"\"}"
,
new
HttpHeaders
(),
HttpStatus
.
CONFLICT
);
return
createErrorResponse
(
"Object already exists."
,
e
.
getMessage
(),
new
HttpHeaders
(),
HttpStatus
.
CONFLICT
);
}
else
if
(
e
instanceof
QueryException
)
{
logger
.
error
(
e
,
e
);
return
new
ResponseEntity
<
Object
>(
"{\"error\" : \"Query server error.\",\"reason\":\""
+
e
.
getMessage
()
+
"\"}"
,
new
HttpHeaders
(),
HttpStatus
.
BAD_REQUEST
);
return
createErrorResponse
(
"Query server error."
,
e
.
getMessage
(),
new
HttpHeaders
(),
HttpStatus
.
BAD_REQUEST
);
}
else
if
(
e
instanceof
ServletRequestBindingException
&&
e
.
getMessage
().
indexOf
(
Configuration
.
AUTH_TOKEN
)
>=
0
)
{
return
new
ResponseEntity
<
Object
>(
"{\"error\" : \"Access denied.\",\"reason\":\""
+
e
.
getMessage
()
+
"\"}"
,
new
HttpHeaders
(),
HttpStatus
.
FORBIDDEN
);
return
createErrorResponse
(
"Access denied."
,
e
.
getMessage
(),
new
HttpHeaders
(),
HttpStatus
.
FORBIDDEN
);
}
else
{
logger
.
error
(
e
,
e
);
return
new
ResponseEntity
<
Object
>(
"{\"error\" : \"Internal server error.\",\"reason\":\""
+
e
.
getMessage
()
+
"\"}"
,
new
HttpHeaders
(),
return
createErrorResponse
(
"Internal server error."
,
e
.
getMessage
(),
new
HttpHeaders
(),
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
}
private
ResponseEntity
<
Object
>
createErrorResponse
(
String
errorMessage
,
String
error
,
HttpHeaders
httpHeaders
,
HttpStatus
status
)
{
return
new
ResponseEntity
<
Object
>(
"{\"error\" : \""
+
errorMessage
+
"\",\"reason\":"
+
new
Gson
().
toJson
(
error
)
+
"}"
,
httpHeaders
,
status
);
}
public
Map
<
String
,
Object
>
parseBody
(
String
body
)
throws
IOException
,
JsonParseException
,
JsonMappingException
{
if
(
body
==
null
||
body
.
isEmpty
())
{
return
new
HashMap
<>();
...
...
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