Skip to Content
avatar image
Former Member

SAPUI5 external api fetch problem

Dear experts,

I have created a simple application using SAP Web IDE FullStack.

In the onInit function of my controller, I am trying to access an external endpoint. My destination is the following:

My neo-app.json looks like this:

{
  "welcomeFile": "/webapp/index.html",
  "routes": [
    {
      "path": "/resources",
      "target": {
        "type": "service",
        "name": "sapui5",
        "entryPath": "/resources"
      },
      "description": "SAPUI5 Resources"
    },
    {
      "path": "/test-resources",
      "target": {
        "type": "service",
        "name": "sapui5",
        "entryPath": "/test-resources"
      },
      "description": "SAPUI5 Test Resources"
    }, {
		"path": "/joke",
		"target": {
			"type": "destination",
			"name": "joke",
			"entryPath": "/"
		},
		"description": ""
	}
  ],
  "sendWelcomeFileRedirect": true
}

controller.js onInit function:

var jokesModel = new JSONModel();

fetch("/joke/jokes/random/15").then(function(data){
     return data.json();
}).then(function(data){
     jokesModel.setData(data.value);
}).catch(function(err){
	MessageToast.show("Something went wrong... " + err);
});

Placing a debugger in the first resolved method shows that my response data is completely wrong:

HTTP 503 - Service Unavailable.

However, if I provide a hard coded URL to the fetch function the GET request will be successful, and then I am able to parse the body and store it without any problem.

Unfortunately I have no idea what causes this error, so any help is appreciated.

dest-scp.jpg (47.9 kB)
fetch-succ.jpg (56.1 kB)
debug-fetch.jpg (92.2 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Nov 03, 2017 at 04:10 AM

    Have you tried configuring the destinations in your neo-app.json file.

    Add comment
    10|10000 characters needed characters exceeded

    • Basically you are not able to read the data only. I think the problem is there with your destinations and configuring them. Could you check them again and try. Check if the destination is connecting or not.