Search code examples
javascriptreact-nativefetch

How to get 2nd line of text response in fetch in react-native


enter image description here

Here I want to display only 2nd line in toast message, so how can I get the 2nd line. I didn't found any solution so please help me.

Here is my API call code:


fetch(`${API_URL}api/${id}`, {
      method: 'get',  
    })
      .then((response) => {
        responseValue = response.status; // this is variable

        return response.text();
      })
      .then((result) => {
        if (responseValue === 500) {
          console.log('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^');
          console.log(result);
        }

      })
      .catch((err) => {
        console.log(err);
      });

hear are error

Exception at /api/5fbf49d35d7473bf278149bc
Folio data not found

Request Method: GET
Request URL: https://example.com/api/barcode/bills/5fbf49d35d7473bf278149bc
Django Version: 3.0.5
Python Executable: /usr/local/bin/uwsgi
Python Version: 3.6.9
   
Exception Type: Exception at /api/
Exception Value: Folio data not found
Request information:
USER: AnonymousUser

GET: No GET data

POST: No POST data

FILES: No FILES data

Solution

  • Try using split as following.

    console.log(error.split('\n')[1]);