USACE / USACE/cwms-data-api

Add Better Error Message for invalid JSON

Open
#869 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
28
Forks
25
Avg merge
4d 22h
Merged PRs (30d)
20

Description

If a user tries to make a POST request with JSON, catch the error and return INVALID JSON. More descriptive error.

Currently you get the generic response, and have to check the logs:

{
  "message": "System Error",
  "incidentIdentifier": "-1457776659434189887",
  "details": {}
}

to which if you go to the error in the logs it is immaculate and I immediately knew the issue.

com.fasterxml.jackson.core.JsonParseException: Unexpected character ('}' (code 125)): was expecting double-quote to start field name

Suggest user test JSON payload in VSCode to verify integrity

I.e.

curl -X 'POST' \
  't7hostnamel:tomcatport/swt-data/auth/keys' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "user-id": "myuserid",
  "key-name": "test"
}'

{
  "user-id": "myuserid",
  "key-name": "test"
},

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the POST endpoint shown in the issue, /swt-data/auth/keys, and trace how the Jackson JsonParseException becomes the generic System Error response. Reproduce the malformed JSON request, then verify that invalid JSON returns a descriptive INVALID JSON response instead of only the incident identifier and empty details.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.