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.

response.text -> response.body

See original GitHub issue
import Koa from 'koa';
import Router from 'koa-router';

export default async function(config: Configuration) {

  const router = new Router();

  router.post('/abcdefg', async ({
    request,
    response
  }) => {

    response.body = '<Settlement><success_code>0</success_code></Settlement>';
    response.set('Content-Type', 'application/xml');
    response.type = 'application/xml';
    response.status = 200;
  });

  return new Koa()
    .use(router.routes())
    .use(router.allowedMethods());
}

returns {} where I expect <Settlement><success_code>0</success_code></Settlement>

this is because response.text has the value <Settlement><success_code>0</success_code></Settlement>. response.body is {}. How can I have the value in response.body?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dead-horsecommented, Sep 11, 2019

this is because response.text has the value <Settlement><success_code>0</success_code></Settlement>. response.body is {}. How can I have the value in response.body?

are you using supertest?

0reactions
gatsbyzcommented, Sep 11, 2019

@dead-horse thanks! where should that parsing go? in supertest?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Response.text() - Web APIs - MDN Web Docs
The text() method of the Response interface takes a Response stream and reads it to completion. It returns a promise that resolves with...
Read more >
javascript - Getting Text From Fetch Response Object
Using the fetch JavaScript API you can try: response.text().then(function (text) { // do something with the text response });. Also take a look...
Read more >
response.text - Python requests
response.text returns the content of the response, in unicode. Basically, it refers to Binary Response content.
Read more >
text - Velo API Reference
Reads the response body as a string. The text() function reads the body response stream to its completion and formats the data as...
Read more >
Fetch
Response provides multiple promise-based methods to access the body in various formats: response.text() – read the response and return as text, ...
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