Duplicate function implementation while creating restful service - swagger
I'm trying to create my service as restful, but when I run Refresh.bat file and run npm start. It gives errors.
[HttpPost("api/services/app/Test")]
public async Task CreateTest(TestDetailsDto input)
[HttpDelete("api/services/app/Test")]
public async Task DeleteTest(EntityDto input)
[HttpGet("api/services/app/Test")]
public async Task GetTest(EntityDto input)
[HttpPut("api/services/app/Test")]
public async Task UpdateTest(TestDetailsDto input)
Errors:
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6197,5): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6230,15): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6252,5): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6267,16): The type argument for type parameter 'R' cannot be inferred
from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'void' is not a valid type argument because it
is not a supertype of candidate 'TestDetailsDto'.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6281,15): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6300,5): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6315,16): The type argument for type parameter 'R' cannot be inferred
from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'number' is not a valid type argument because
it is not a supertype of candidate 'TestDetailsDto'.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6329,15): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6351,5): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6370,16): The type argument for type parameter 'R' cannot be inferred
from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'void' is not a valid type argument because it
is not a supertype of candidate 'TestDetailsDto'.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6384,15): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/app/merchandising/Tests/Test-list.component.ts
(210,45): Property 'deleteTest' does not exist on type
'TestServiceProxy'.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/app/merchandising/Tests/Test-main.component.ts
(102,41): Property 'getTestDetailsforEdit' does not exist on type
'TestServiceProxy'.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/app/merchandising/Tests/Test-main.component.ts
(163,37): Property 'createTest' does not exist on type
'TestServiceProxy'.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/app/merchandising/Tests/Test-main.component.ts
(206,37): Property 'createTest' does not exist on type
'TestServiceProxy'.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/app/merchandising/Tests/Test-main.component.ts
(218,37): Property 'updateTest' does not exist on type
'TestServiceProxy'.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6197,5): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6230,15): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6252,5): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6267,16): The type argument for type parameter 'R' cannot be inferred
from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'void' is not a valid type argument because it
is not a supertype of candidate 'TestDetailsDto'.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6281,15): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6300,5): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6315,16): The type argument for type parameter 'R' cannot be inferred
from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'number' is not a valid type argument because
it is not a supertype of candidate 'TestDetailsDto'.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6329,15): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6351,5): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6370,16): The type argument for type parameter 'R' cannot be inferred
from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'void' is not a valid type argument because it
is not a supertype of candidate 'TestDetailsDto'.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/shared/service-proxies/service-proxies.ts
(6384,15): Duplicate function implementation.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/app/merchandising/Tests/Test-list.component.ts
(210,45): Property 'deleteTest' does not exist on type
'TestServiceProxy'.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/app/merchandising/Tests/Test-main.component.ts
(102,41): Property 'getTestDetailsforEdit' does not exist on type
'TestServiceProxy'.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/app/merchandising/Tests/Test-main.component.ts
(163,37): Property 'createTest' does not exist on type
'TestServiceProxy'.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/app/merchandising/Tests/Test-main.component.ts
(206,37): Property 'createTest' does not exist on type
'TestServiceProxy'.
ERROR in
C:/Users/MyName/source/repos/Stanchion/angular/src/app/merchandising/Tests/Test-main.component.ts
(218,37): Property 'updateTest' does not exist on type
'TestServiceProxy'.
Service.Swag.Config file:
{
"swaggerGenerator": {
"fromSwagger": {
"url": "http://localhost:22742/swagger/v1/swagger.json",
"output": null
}
},
"codeGenerators": {
"swaggerToTypeScriptClient": {
"className": "{controller}ServiceProxy",
"moduleName": "",
"namespace": "",
"typeScriptVersion": 1.8,
"template": "Angular",
"promiseType": "Promise",
"dateTimeType": "MomentJS",
"nullValue": "Undefined",
"generateClientClasses": true,
"generateClientInterfaces": false,
"generateOptionalParameters": false,
"wrapDtoExceptions": false,
"useTransformOptionsMethod": false,
"useTransformResultMethod": false,
"generateDtoTypes": true,
"operationGenerationMode": "MultipleClientsFromPathSegments",
"markOptionalProperties": false,
"generateCloneMethod": false,
"typeStyle": "Class",
"extensionCode": "service.extensions.ts",
"generateDefaultValues": true,
"excludedTypeNames": [],
"handleReferences": false,
"generateConstructorInterface": true,
"importRequiredTypes": true,
"baseUrlTokenName": "API_BASE_URL",
"output": "../src/shared/service-proxies/service-proxies.ts"
},
"swaggerToCSharpClient": {
"generateClientClasses": true,
"generateClientInterfaces": false,
"generateDtoTypes": true,
"injectHttpClient": false,
"disposeHttpClient": true,
"generateExceptionClasses": true,
"exceptionClass": "SwaggerException",
"wrapDtoExceptions": true,
"useHttpClientCreationMethod": false,
"httpClientType": "System.Net.Http.HttpClient",
"useHttpRequestMessageCreationMethod": false,
"useBaseUrl": true,
"generateSyncMethods": false,
"clientClassAccessModifier": "public",
"generateContractsOutput": false,
"className": "{controller}Client",
"namespace": "MyNamespace",
"generateOptionalParameters": false,
"requiredPropertiesMustBeDefined": true,
"dateType": "System.DateTime",
"dateTimeType": "System.DateTime",
"timeType": "System.TimeSpan",
"timeSpanType": "System.TimeSpan",
"arrayType": "System.Collections.ObjectModel.ObservableCollection",
"dictionaryType": "System.Collections.Generic.Dictionary",
"classStyle": "Inpc",
"operationGenerationMode": "MultipleClientsFromOperationId",
"generateDefaultValues": true,
"generateDataAnnotations": true,
"excludedTypeNames": [],
"wrapResponses": false,
"generateResponseClasses": true,
"responseClass": "SwaggerResponse",
"handleReferences": false,
"generateImmutableArrayProperties": false,
"generateImmutableDictionaryProperties": false,
"output": null
},
"swaggerToCSharpController": {
"className": "{controller}",
"namespace": "MyNamespace",
"additionalNamespaceUsages": [
"System.Web.Http"
],
"generateOptionalParameters": false,
"requiredPropertiesMustBeDefined": true,
"dateType": "System.DateTime",
"dateTimeType": "System.DateTime",
"timeType": "System.TimeSpan",
"timeSpanType": "System.TimeSpan",
"arrayType": "System.Collections.Generic.IEnumerable",
"dictionaryType": "System.Collections.Generic.Dictionary",
"classStyle": "Inpc",
"operationGenerationMode": "MultipleClientsFromOperationId",
"generateDefaultValues": true,
"generateDataAnnotations": true,
"excludedTypeNames": [],
"wrapResponses": false,
"generateResponseClasses": true,
"responseClass": "SwaggerResponse",
"handleReferences": false,
"generateImmutableArrayProperties": false,
"generateImmutableDictionaryProperties": false,
"output": null
}
}
}
I have "nswag": "10.6.0" version.
Its giving errors in for these methods in service-proxies.ts file.
export class AppServiceProxy {
private http: Http;
private baseUrl: string;
protected jsonParseReviver: (key: string, value: any) => any = undefined;
constructor(#Inject(Http) http: Http, #Optional() #Inject(API_BASE_URL) baseUrl?: string) {
this.http = http;
this.baseUrl = baseUrl ? baseUrl : "";
}
/**
* #return Success
*/
Test(id: number): Observable<TestDetailsDto> {
let url_ = this.baseUrl + "/api/services/app/Test?";
if (id === undefined || id === null)
throw new Error("The parameter 'id' must be defined and cannot be null.");
else
url_ += "Id=" + encodeURIComponent("" + id) + "&";
url_ = url_.replace(/[?&]$/, "");
const content_ = "";
let options_ = {
body: content_,
method: "get",
headers: new Headers({
"Content-Type": "application/json; charset=UTF-8",
"Accept": "application/json; charset=UTF-8"
})
};
return this.http.request(url_, options_).flatMap((response_) => {
return this.processTest(response_);
}).catch((response_: any) => {
if (response_ instanceof Response) {
try {
return this.processTest(response_);
} catch (e) {
return <Observable<TestDetailsDto>><any>Observable.throw(e);
}
} else
return <Observable<TestDetailsDto>><any>Observable.throw(response_);
});
}
protected processTest(response: Response): Observable<TestDetailsDto> {
const status = response.status;
if (status === 200) {
const responseText = response.text();
let result200: TestDetailsDto = null;
let resultData200 = responseText === "" ? null : JSON.parse(responseText, this.jsonParseReviver);
result200 = resultData200 ? TestDetailsDto.fromJS(resultData200) : new TestDetailsDto();
return Observable.of(result200);
} else if (status === 401) {
const responseText = response.text();
return throwException("A server error occurred.", status, responseText);
} else if (status !== 200 && status !== 204) {
const responseText = response.text();
return throwException("An unexpected server error occurred.", status, responseText);
}
return Observable.of<TestDetailsDto>(<any>null);
}
/**
* #return Success
*/
Test(input: TestDetailsDto): Observable<void> {
let url_ = this.baseUrl + "/api/services/app/Test";
url_ = url_.replace(/[?&]$/, "");
const content_ = JSON.stringify(input ? input.toJSON() : null);
let options_ = {
body: content_,
method: "put",
headers: new Headers({
"Content-Type": "application/json; charset=UTF-8",
"Accept": "application/json; charset=UTF-8"
})
};
return this.http.request(url_, options_).flatMap((response_) => {
return this.processTest(response_);
}).catch((response_: any) => {
if (response_ instanceof Response) {
try {
return this.processTest(response_);
} catch (e) {
return <Observable<void>><any>Observable.throw(e);
}
} else
return <Observable<void>><any>Observable.throw(response_);
});
}
protected processTest(response: Response): Observable<void> {
const status = response.status;
if (status === 200) {
const responseText = response.text();
return Observable.of<void>(<any>null);
} else if (status === 401) {
const responseText = response.text();
return throwException("A server error occurred.", status, responseText);
} else if (status !== 200 && status !== 204) {
const responseText = response.text();
return throwException("An unexpected server error occurred.", status, responseText);
}
return Observable.of<void>(<any>null);
}
/**
* #return Success
*/
Test(input: TestDetailsDto): Observable<number> {
let url_ = this.baseUrl + "/api/services/app/Test";
url_ = url_.replace(/[?&]$/, "");
const content_ = JSON.stringify(input ? input.toJSON() : null);
let options_ = {
body: content_,
method: "post",
headers: new Headers({
"Content-Type": "application/json; charset=UTF-8",
"Accept": "application/json; charset=UTF-8"
})
};
return this.http.request(url_, options_).flatMap((response_) => {
return this.processTest(response_);
}).catch((response_: any) => {
if (response_ instanceof Response) {
try {
return this.processTest(response_);
} catch (e) {
return <Observable<number>><any>Observable.throw(e);
}
} else
return <Observable<number>><any>Observable.throw(response_);
});
}
protected processTest(response: Response): Observable<number> {
const status = response.status;
if (status === 200) {
const responseText = response.text();
let result200: number = null;
let resultData200 = responseText === "" ? null : JSON.parse(responseText, this.jsonParseReviver);
result200 = resultData200 !== undefined ? resultData200 : <any>null;
return Observable.of(result200);
} else if (status === 401) {
const responseText = response.text();
return throwException("A server error occurred.", status, responseText);
} else if (status !== 200 && status !== 204) {
const responseText = response.text();
return throwException("An unexpected server error occurred.", status, responseText);
}
return Observable.of<number>(<any>null);
}
/**
* #return Success
*/
Test(id: number): Observable<void> {
let url_ = this.baseUrl + "/api/services/app/Test?";
if (id === undefined || id === null)
throw new Error("The parameter 'id' must be defined and cannot be null.");
else
url_ += "Id=" + encodeURIComponent("" + id) + "&";
url_ = url_.replace(/[?&]$/, "");
const content_ = "";
let options_ = {
body: content_,
method: "delete",
headers: new Headers({
"Content-Type": "application/json; charset=UTF-8",
"Accept": "application/json; charset=UTF-8"
})
};
return this.http.request(url_, options_).flatMap((response_) => {
return this.processTest(response_);
}).catch((response_: any) => {
if (response_ instanceof Response) {
try {
return this.processTest(response_);
} catch (e) {
return <Observable<void>><any>Observable.throw(e);
}
} else
return <Observable<void>><any>Observable.throw(response_);
});
}
protected processTest(response: Response): Observable<void> {
const status = response.status;
if (status === 200) {
const responseText = response.text();
return Observable.of<void>(<any>null);
} else if (status === 401) {
const responseText = response.text();
return throwException("A server error occurred.", status, responseText);
} else if (status !== 200 && status !== 204) {
const responseText = response.text();
return throwException("An unexpected server error occurred.", status, responseText);
}
return Observable.of<void>(<any>null);
}
}
Related
Send Blob over POST http request with string values
Hi I am trying to do a http POST request to send some blob data. But I also need to send some string values with it for authentication (jwt). let options = {uname: user.uname, authKey: user.authKey, video: qde.debrief.blob} let xhr = await xhrRequest(`${serverIp}/api/file`, "POST", options, 'none'); prom.push(xhr); And the xhrRequest method is //xhr function with url input and isValid and data output function xhrRequest(url, type, body, header) { return new Promise((resolve, reject) => { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { resolve({ error: false, body: JSON.parse(xhr.response) }); } else if (xhr.readyState === 4 && xhr.status !== 200) { resolve({ error: true, body: JSON.parse(xhr.response) }); } } xhr.timeout = 5000; xhr.ontimeout = () => { resolve({ error: true, body: "Error Connecting to server" }); } xhr.onerror = function () { resolve({ error: true, body: "Error Connecting to server" }); } xhr.open(type, url, true); if (type == "POST") { if(!header){ xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); } xhr.send(body) } else { xhr.send(); } }) }
"errorType": "TypeError", "errorMessage": "Cannot set property 'createCertificate' of undefined"
odule.export.createCertificate = async (event, context, cb) => { let data = JSON.parse(event.body); try{ const params = { TableName: CERTIFICATE_TABLE_NAME, Item:{ certificationId: data.id, certificationName: data.certificationName, certificationProvider: data.certificationProvider, certificationLevel: data.certificationLevel, certificationValidationId: data.certificationValidationId, dateOfCertification: data.dateOfCertification, dateOfExpiry: data.dateOfExpiry }, ConditionExpression: "attribute_not_exists(certificationId)" } await documentClient.put(params).promise(); cb(null,{ statusCode: 201, body: JSON.stringify(data) }); }catch(err){ cb(null,{ statusCode: 500, body: JSON.stringify(err.message) }); } }; module.export.createCertificate I having an handler above and I figured I haven't defined the createCertifiacte but How I would define I couldn't know
HTTP request is returns 400, but cannot throw error
Trying to use this request post function. When I run it with the correct requestBody it works fine, but if the requestBody is invalid it returns a HTTP 400 and fails, but no matter what I try to throw, or as such, the catch block never runs. Can anyone help? This is in Node and using the request package. const res = async() => { try { const res = await request({ method: "POST", url: "url", headers: { "content-type": "application/json", "authorization": "Basic " + Buffer.from(username + ":" + password).toString("base64") }, body: JSON.stringify(requestBody) }, function(error, response, data) { if(response.statusCode == 201 || response.statusCode == 200) { console.log(data); } else { console.log("Fell into else block!"); throw new Error("POST failed!"); } }); } catch (error) { console.log("something went wrong!", error); } };
Since request function returns a promise use catch method const res = await request({ method: "POST", url: "url", headers: { "content-type": "application/json", "authorization": "Basic " + Buffer.from(username + ":" + password).toString("base64") }, body: JSON.stringify(requestBody) }, function(error, response, data) { if(response.statusCode == 201 || response.statusCode == 200) { console.log(data); } else { console.log("Fell into else block!"); throw new Error("POST failed!"); } }) .catch((error) => { console.log("something went wrong!", error); });
Alexa skill testing error: Error handled: Cannot read property 'value' of undefined
Please help me if any body resolved the issue and below is my lambda funciton code. when i comment all funcitons in exports.handler funciton and execute/test single function it is working but if we enable all funcitons then i am getting the error as Error handled: Cannot read property 'value' of undefined Node JS code for alexa skill kit for different intents created. GetNewFactHandler, CreateJIRAIssueHandler, UpdateJIRAIssueHandler, GetJIRAIssueHandler, GetJIRAIssueCountHandler, /* eslint-disable func-names */ /* eslint-disable no-console */ var http = require('http'); var https = require('https'); var projectKey=''; var iType=''; var keyValueID=''; var userName=''; var IssueNumber=''; const Alexa = require('ask-sdk'); const GetNewFactHandler = { canHandle(handlerInput) { const request = handlerInput.requestEnvelope.request; return request.type === 'LaunchRequest' || (request.type === 'IntentRequest' && request.intent.name === 'GetNewFactIntent'); }, handle(handlerInput) { const factArr = data; const factIndex = Math.floor(Math.random() * factArr.length); const randomFact = factArr[factIndex]; const speechOutput = GET_FACT_MESSAGE + randomFact; return handlerInput.responseBuilder .speak(speechOutput) .withSimpleCard(SKILL_NAME, randomFact) .getResponse(); }, }; var reqTimeout = 3000; const CreateJIRAIssueHandler = { canHandle(handlerInput) { const request = handlerInput.requestEnvelope.request; const proKey = request.intent.slots.PROJECTKEY.value; const issueType = request.intent.slots.ISSUETYPE.value; iType = capitalize_Words(issueType); projectKey = proKey.toUpperCase(); return request.type === 'IntentRequest' && request.intent.name === 'CreateJIRAIssue'; }, async handle(handlerInput) { const createIssue = await createJiraIssue(projectKey, iType); const speechOutput = JSON.parse(createIssue).key; return handlerInput.responseBuilder .speak('Issue ' + speechOutput + ' created') .getResponse(); }, }; function capitalize_Words(str) { return str.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); }); }; //mule real time server var muleCreateIssuePath = '/jira/createissue'; var muleProtocol = 'https'; var createIssueMethod = 'POST'; var muleUpdateIssuePath = '/jira/issue/'; var updateIssueMethod = 'PUT'; var getIssueMethod = 'GET'; var MuleReqOpts = { host: '', port: 443, path: undefined, // To be set. method: undefined, headers: { 'Content-Type': 'application/json' }, agent: false, // auth: jiraUsername + ':' + jiraPassword auth: '' }; var MuleHttp = muleProtocol === 'https' ? https : http; function createJiraIssue(projectKey, iType) { MuleReqOpts.path = muleCreateIssuePath; MuleReqOpts.method = createIssueMethod; var MuleReqBody = { 'fields': { 'project': { 'key': projectKey }, 'summary': 'Test Message', 'description': 'Issue created for alexa skill kit from Integration alexa to jira', 'issuetype': { 'name': iType // Make sure your JIRA project configuration(s) supports this Issue Type. } } }; return doApiCall(MuleHttp, MuleReqOpts, MuleReqBody, 'creating issue', 201); }; function doApiCall(httplib, reqOpts, reqBody, happening, successCode) { return new Promise(((resolve, reject) => { var req = httplib.request(reqOpts, (res) => { res.setEncoding('utf8'); let returnData = ''; res.on('data', (chunk) => { returnData += chunk; }); res.on('end', () => { resolve(returnData); }); res.on('error', (error) => { reject(error); }); }); req.write(JSON.stringify(reqBody)); req.end(); req.on('error', function(err) { context.done(new Error(' request error: ' + err.message)); }); req.setTimeout(reqTimeout, function() { context.done(new Error(' request timeout after ' + reqTimeout + ' milliseconds.')); }); })); }; const UpdateJIRAIssueHandler = { canHandle(handlerInput) { console.log('1'); const request = handlerInput.requestEnvelope.request; console.log('2'); userName = request.intent.slots.USER.value; var keyValue = request.intent.slots.PROJECTKEY.value; console.log('keyValue : ' + keyValue); keyValueID = keyValue.toUpperCase(); IssueNumber = request.intent.slots.ISSUENUMBER.value; let INumber = Number(IssueNumber); console.log('IssueNumber value: '+INumber); console.log('key value id: ' + keyValueID); return request.type === 'IntentRequest' && request.intent.name === 'UpdateJIRAIssue'; }, async handle(handlerInput) { const updateIssue = await updateJiraIssue(userName); console.log('updateIssue log: ' + updateIssue); const speechOutput = JSON.parse(updateIssue).responseMessage; console.log('speechOutput log: ' + speechOutput); return handlerInput.responseBuilder .speak(speechOutput) .getResponse(); }, }; function updateJiraIssue(userName) { console.log('inside method: ' +userName); MuleReqOpts.method = updateIssueMethod; var postdata = { "fields": { "assignee": { "name": userName } } } return doApiUpdateCall(MuleHttp, MuleReqOpts, postdata, 'updating issue', 201); }; function doApiUpdateCall(httplib, options, postdata, happening, successCode) { options.path = muleUpdateIssuePath + keyValueID +'-'+IssueNumber ; return new Promise(((resolve, reject) => { var req = httplib.request(options, (res) => { console.log(options); res.setEncoding('utf8'); let returnData = ''; res.on('data', (body) => { returnData += body; console.log(returnData); }); res.on('end', () => { resolve(returnData); }); console.log('1'); console.log('Body: '); }); req.on('error', function(e) { console.log('problem with request: ' + e.message); }); var jirapostString = JSON.stringify(postdata); console.log(jirapostString); req.write(jirapostString); req.end(); })); }; const GetJIRAIssueHandler = { canHandle(handlerInput) { console.log('1'); const request = handlerInput.requestEnvelope.request; var keyValue = request.intent.slots.Issue.value; console.log('keyValue: ' + keyValue); keyValueID = keyValue.toUpperCase(); return request.type === 'IntentRequest' && request.intent.name === 'GetJIRAIssue'; }, async handle(handlerInput) { const getIssue = await GetJIRAIssue(); console.log('getIssue log: ' + getIssue); const assigneeName = JSON.parse(getIssue).fields.assignee.name; const key = JSON.parse(getIssue).fields.assignee.key; const reporterName = JSON.parse(getIssue).fields.reporter.name; const issueType = JSON.parse(getIssue).fields.issuetype.name; const projectName = JSON.parse(getIssue).fields.project.name; const summaryDetails = JSON.parse(getIssue).fields.summary; const speechOutput = 'Here are the issue details summary: Assignee : ' + assigneeName.concat(' ,reporter : ' + reporterName, ' ,Issue Key : ' + key, ' ,IssueType : ' + issueType, ' ,ProjectName : ' + projectName, ' ,Summary : ' + summaryDetails); console.log('speechOutput log: ' + speechOutput); return handlerInput.responseBuilder .speak(speechOutput) .getResponse(); }, }; function GetJIRAIssue() { MuleReqOpts.method = getIssueMethod; return doApiGetIssueCall(MuleHttp, MuleReqOpts, 'get issue details', 201); }; function doApiGetIssueCall(httplib, options, happening, successCode) { options.path = muleUpdateIssuePath + keyValueID; return new Promise(((resolve, reject) => { https.get(options, (res) => { console.log(options); res.setEncoding('utf8'); let returnData = ''; res.on('data', (body) => { returnData += body; console.log('response :', returnData); }); res.on('end', () => { resolve(returnData); }); }); })); }; const GetJIRAIssueCountHandler = { canHandle(handlerInput) { const request = handlerInput.requestEnvelope.request; userName = request.intent.slots.USER.value; console.log('userName Value: ' + userName); const issueType = request.intent.slots.ISSUETYPE.value; iType = capitalize_Words(issueType); return request.type === 'IntentRequest' && request.intent.name === 'GetJIRAIssueCount'; }, async handle(handlerInput) { const getIssueCount = await GetJIRAIssueCount(); console.log('getIssue log: ' + getIssueCount); const total = JSON.parse(getIssueCount).total; const speechOutput = ('Here is the '+iType+' count details: ' +total ); console.log('speechOutput log: ' + speechOutput); return handlerInput.responseBuilder .speak(speechOutput) .getResponse(); }, }; function GetJIRAIssueCount() { MuleReqOpts.method = getIssueMethod; return doApiGetIssueCountCall(MuleHttp, MuleReqOpts, 'get issue count details', 201); }; function doApiGetIssueCountCall(httplib, options, happening, successCode) { options.path = muleUpdateIssuePath + userName +'/'+iType; return new Promise(((resolve, reject) => { https.get(options, (res) => { console.log(options); res.setEncoding('utf8'); let returnData = ''; res.on('data', (body) => { returnData += body; console.log('response :', returnData); }); res.on('end', () => { resolve(returnData); }); }); })); }; const HelpHandler = { canHandle(handlerInput) { const request = handlerInput.requestEnvelope.request; return request.type === 'IntentRequest' && request.intent.name === 'AMAZON.HelpIntent'; }, handle(handlerInput) { return handlerInput.responseBuilder .speak(HELP_MESSAGE) .reprompt(HELP_REPROMPT) .getResponse(); }, }; const ExitHandler = { canHandle(handlerInput) { const request = handlerInput.requestEnvelope.request; return request.type === 'IntentRequest' && (request.intent.name === 'AMAZON.CancelIntent' || request.intent.name === 'AMAZON.StopIntent'); }, handle(handlerInput) { return handlerInput.responseBuilder .speak(STOP_MESSAGE) .getResponse(); }, }; const SessionEndedRequestHandler = { canHandle(handlerInput) { const request = handlerInput.requestEnvelope.request; return request.type === 'SessionEndedRequest'; }, handle(handlerInput) { console.log(`Session ended with reason: ${handlerInput.requestEnvelope.request.reason}`); return handlerInput.responseBuilder.getResponse(); }, }; const ErrorHandler = { canHandle() { return true; }, handle(handlerInput, error) { console.log(`Error handled: ${error.message}`); return handlerInput.responseBuilder .speak('Sorry, an error occurred.') .reprompt('Sorry, an error occurred.') .getResponse(); }, }; const SKILL_NAME = 'Space Facts'; const GET_FACT_MESSAGE = 'Here\'s your fact: '; const HELP_MESSAGE = 'You can say tell me a space fact, or, you can say exit... What can I help you with?'; const HELP_REPROMPT = 'What can I help you with?'; const STOP_MESSAGE = 'Goodbye!'; const data = [ 'A year on Mercury is just 88 days long.', 'Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.', 'Venus rotates counter-clockwise, possibly because of a collision in the past with an asteroid.', 'On Mars, the Sun appears about half the size as it does on Earth.', 'Earth is the only planet not named after a god.', 'Jupiter has the shortest day of all the planets.', 'The Milky Way galaxy will collide with the Andromeda Galaxy in about 5 billion years.', 'The Sun contains 99.86% of the mass in the Solar System.', 'The Sun is an almost perfect sphere.', 'A total solar eclipse can happen once every 1 to 2 years. This makes them a rare event.', 'Saturn radiates two and a half times more energy into space than it receives from the sun.', 'The temperature inside the Sun can reach 15 million degrees Celsius.', 'The Moon is moving approximately 3.8 cm away from our planet every year.', ]; const skillBuilder = Alexa.SkillBuilders.custom(); exports.handler = skillBuilder .addRequestHandlers( GetNewFactHandler, CreateJIRAIssueHandler, UpdateJIRAIssueHandler, GetJIRAIssueHandler, GetJIRAIssueCountHandler, HelpHandler, ExitHandler, SessionEndedRequestHandler ) .addErrorHandlers(ErrorHandler) .lambda();
Check all of your code for instances where you are looking for someObject.someNestedProperty.value. I suspect that your slot values in your Intents are not the same as defined in your model/some-LANG.json file. Trying to access value property from someObject without a someNestedProperty will cause your error (i.e. request.intent.slots.PROJECTKEY.value). If this is a Alexa-hosted skill, CloudWatch logging is built right in. Open the Alexa Developer Console, edit your skill, then go to the Code tab. On the bottom left, you should see a link for Logs: Amazon CloudWatch. You can log anything you want with a simple console.log() statement. Also, be aware that the ask-sdk-core npm package contains helper methods to get slotValues (among other great tools). For more information, see this link: https://developer.amazon.com/en-US/docs/alexa/alexa-skills-kit-sdk-for-nodejs/utilities.html
Thanks all for your suggestions and prompt response. Now the issue is resolved and the solution is the addRequestHandlers method will execute methods sequentially even if you execute/trigger third handler it will execute 1st and 2nd and goes to 3rd one. Here the issue is when you trigger a 3rd handler command from alexa it will passs the slot values related to the 3rd handler utterance and hence the 1st and 2nd haldler having slot values are not able to resolve and failed. so i put a condition overthere to skip 1st and 2nd handler execution and it worked.
Knockout Validation Plugin Custom Error Message
Based on the following, how exactly do I setup the callback to display a custom error message instead of the default message? ko.validation.rules['exampleAsync'] = { async: true, // the flag that says "Hey I'm Async!" validator: function (val, otherVal, callBack) { // yes, you get a 'callback' /* some logic here */ // hand my result back to the callback callback( /* true or false */ ); // or if you want to specify a specific message callback( /* { isValid: true, message: "Lorem Ipsum" } */ ); }, message: 'My default invalid message' };
ko.validation.rules['exampleAsync'] = { async: true, validator: function (val, otherVal, callBack) { // make an ajax call or something here to do your async validation $.ajax({ type: 'post', url: 'some url', data: val, success: function (data) { if (data.success) { callback({ isValid: true, message: "yay it worked"}); } else { callback({ isValid: false, message: data.message }); } }); }, message: 'My default invalid message' };