question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should not need to be generated JSON.parse or using it incorrectly?

See original GitHub issue

image image

Code.

public async Task<string> TypeScript()
        {
            string baseUrl = $"{this.Request.Scheme}://{this.Request.Host.Value.ToString()}{this.Request.PathBase.Value.ToString()}";
            OpenApiDocument document = await OpenApiDocument.FromUrlAsync($"{baseUrl}/swagger/v1/swagger.json");          
            var settings = new TypeScriptClientGeneratorSettings
            {
                TypeScriptGeneratorSettings = {                  
                    TypeScriptVersion = 3.9M,
                    TypeStyle = TypeScriptTypeStyle.Interface,// Interface,Class or KoObservableClass
                    DateTimeType = TypeScriptDateTimeType.String,//Date, MomentJS or String
                }, 
                Template = TypeScriptTemplate.Axios,
                PromiseType = PromiseType.Promise,
                HttpClass = HttpClass.HttpClient,
                ClassName = "{controller}Client",
            };

            var generator = new TypeScriptClientGenerator(document, settings);
            var code = generator.GenerateFile();
            return code;
        }

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
Liwojcommented, Mar 18, 2021

It is true that current version of Axios is using JSON.parse by default thanks to it’s default transformResponse but is is also true the implementation is flawed big way as it swallows any error from parsing. Check this 6 years old! issue

So it is a good idea to disable it anyway. Just pass transformResponse: [] into axios.create

1reaction
RicoSutercommented, May 7, 2021

I do not use Axios in any projects so I do not what to do here… Can someone create a PR with a fix for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling bad JSON.parse() in node safely
The best way to catch invalid JSON parsing errors is to put the calls to JSON.parse() to a try/catch block. You really do...
Read more >
Anything wrong with direct evaluation of JSON if your own ...
Suppose I have a server-side variable containing JSON, called strJSON that my own code created. Was it created entirely by your code?
Read more >
How to Parse Improperly Formatted JSON Objects in ...
Therefore, the problem to solve is to take an invalid text file with valid JSON objects and properly format it for parsing. Instead...
Read more >
Error while parsing JSON Response in REST API Post call
I am using Outsystems 10 and trying to consume a REST API (single method). I have copied and pasted the REST Request and...
Read more >
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found