0

I'm using Angular 4 and a Spring service that I throws an exception with the message being the toString of a List of messages. The problem is that when I receive the exception response and extract the message, instead of being treated like an Array of strings, it's treated as a single string in the format of: "[message 1, message 2]"

Is there a way in typescript to easily convert this String into an array of strings? I tried instantiating a new Array with the string like: new Array(errorResponse.error.message); but that didn't really work.

2

2 Answers 2

8

It should working for you:

var messages = message.substring(1, message.length-1).split(", ");

Fiddle with a function, which doing this is available here.

Sign up to request clarification or add additional context in comments.

Comments

0

It works with JSON.Parse("[message 1, message 2]");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.