Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private async promoteNews(pageName: string, pageType:string, newsstatus: string, siteUrl: string): Promise<string> {
var functionUrl : string = "<azure function url>"
const requestHeaders: Headers = new Headers();
requestHeaders.append("Content-type", "application/json");
requestHeaders.append("Cache-Control", "no-cache");
const postOptions : RequestInit = {
headers: requestHeaders,
body: `{\r\n siteURL: '${siteUrl}',\r\n pageType: '${pageType}', \r\n pageName: '${pageName}', \r\n pageStatus: 'edit', \r\n newsStatus: '${newsstatus}'\r\n}`,
method: "POST"
};
let responseText: string = "";
let createPageStatus: string = "";
console.log('Wait started');
await fetch(functionUrl, postOptions).then((response) => {
console.log('Response returned');
if (response.ok) {
return response.json()
}
else
{
var errMsg = "Error detected while updating site page. Server response wasn't OK ";
console.log(errMsg);
createPageStatus = "failed";
}
}).then((responseJSON: JSON) => {
responseText = JSON.stringify(responseJSON).trim();
console.log(responseText);
if(responseText.toLowerCase().indexOf("uccess") > 0)
{
console.log("setting");
createPageStatus = "success";
}
if(responseText.toLowerCase().indexOf("rror") > 0)
{
console.log("errored");
createPageStatus = "error";
}
}
).catch ((response: any) => {
let errMsg: string = `WARNING - error when calling URL ${functionUrl}. Error = ${response.message}`;
console.log(errMsg);
createPageStatus = "failed";
});
console.log("Wait finished");
return createPageStatus;
}
@Szab
Copy link

Szab commented Jun 13, 2018

responseText.toLowerCase().indexOf("uccess") > 0
responseText.toLowerCase().indexOf("rror") > 0

what the fuck?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment