Skip to content

Improve JSON parse error handling #194

Description

@kd-ods

Describe the bug

At the moment, when the JSON is invalid, the paste-box is emptied and replaced with the text 'undefined'.

This is not user-friendly: users don't know what's caused the problem and they aren't assisted to recover from it.

To Reproduce

Steps to reproduce the behaviour:

  1. Paste the following into the visualiser and click draw
[
  {
    "statementId": "1dc0e987-5c57-4a1c-b3ad-61353b66a9b7",
    "declarationSubject": "c359f58d2977",
    "statementDate": "2020-03-04",
    "publicationDetails": {
      "bodsVersion": "0.4"
    },
    "recordId": "c359f58d2977",
    "recordStatus": "new",
    "recordType": "entity",
    "recordDetails": {
      "name": "Profitech Ltd",
      "foundingDate": "2019-09-03"
    }
  },
  {
    "statementId": "019a93f1-e470-42e9-957b-03559861b2e2",
    "declarationSubject": "c359f58d2977",
    "statementDate": "2020-03-04",
    "publicationDetails": {
      "bodsVersion": "0.4"
    },
    "recordId": "10478c6cf6de",
    "recordStatus": "new",
    "recordType": "person",
    "recordDetails": {
      "personType": "knownPerson",
      "names": [
        {
          "type": "legal",
          "fullName": "Jennifer Hewitson-Smith",
          "givenName": "Jennifer",
          "familyName": "Hewitson-Smith"
        }
      ]
    }
  },
  {
    "statementId": "fbfd0547-d0c6-4a00-b559-5c5e91c34f5c",
    "declarationSubject": "c359f58d2977",
    "statementDate": "2020-03-04",
    "publicationDetails": {
      "bodsVersion": "0.4"
    },
    "recordId": "93b53022ae6a",
    "recordStatus": "new",
    "recordType": "relationship",
    "recordDetails": {
      "subject": "c359f58d2977",
      "interestedParty": "10478c6cf6de"
      "interests": [
        {}
      ]
    }
  }
]

(There is a missing comma at the end of '"interestedParty": "10478c6cf6de"', 7 lines from the bottom.)

Expected behaviour

Ideally:

  • On clicking 'Draw', an alert box would appear, saying 'The JSON is not valid. [...]' and then simply pass on the error message. (So in the above case: 'The JSON is not valid. SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 52 column 7 of the JSON data')
  • The JSON data would remain in the paste-box, so that once the error message is dismissed, the data can be corrected.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions