I'm trying to implement the Alexa.Speaker interface with the Node.js v2 sdk.
When testing, I always get the output: There was a problem with the requested skill's response and this error in my CloudWatch logs:
{
"type": "SessionEndedRequest",
"requestId": "amzn1.echo-api.request.bf854d70-70c1-4e7f-b2b0-76c4574244a5",
"timestamp": "2018-10-22T16:58:12Z",
"locale": "en-US",
"reason": "ERROR",
"error": {
"type": "INVALID_RESPONSE",
"message": "An exception occurred while dispatching the request to the skill."
}
}
Here's my code.
return handlerInput.responseBuilder
.addDirective({
type: 'Alexa.Speaker',
name: 'SetVolume',
payload: {
volume: volume,
},
token: 'correlationToken',
})
.getResponse();
I've implemented the Connections.SendRequest interface in this way before, so I'm not sure what's wrong/different with Alexa.Speaker.
Related
is there a way how to run an exception through the apollo exception handler manually?
I have 90% of the application in GraphQL but still have two modules as REST and I'd like to unify the way the exceptions are handled.
So the GQL queries throw the standard 200 with errors array containing message, extensions etc.
{
"errors": [
{
"message": { "statusCode": 401, "error": "Unauthorized" },
"locations": [{ "line": 2, "column": 3 }],
"path": [ "users" ],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"response": { "statusCode": 401, "error": "Unauthorized" },
"status": 401,
"message": { "statusCode": 401, "error": "Unauthorized" }
}
}
}
],
"data": null
}
where the REST throws the real 401 with JSON:
{
"statusCode": 401,
"error": "Unauthorized"
}
So can I simply catch and wrap the exception in the Apollo Server format or do I have to format my REST errors manually? Thanks
I am using NestJS and the GraphQL module.
You can set up a custom exception filter which catches the REST-Api errors and wraps them in the Apollo Server format. Something like:
#Catch(RestApiError)
export class RestApiErrorFilter implements ExceptionFilter {
catch(exception: RestApiError, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse();
const status = 200;
response
.status(status)
.json(RestApiErrorFilter.getApolloServerFormatError(exception);
}
private static getApolloServerFormatError(exception: RestApiErrorFilter) {
return {}; // do your conversion here
}
👋I just started playing around with Swagger and everything is amazing. I was able to document all API in an hour or so but I got stuck solving one last issue.
How can I tell swagger to show ApiBadRequestResponse in the format below?
#ApiOkResponse({
type: User,
})
#ApiBadRequestResponse({
type: {
error: String,
message: ValidationError[]
}
})
#Post('/signup')
signUp(
#Body(ValidationPipe) authCredentialsDto: CredentialsDTO
): Promise<User> {
return this.userService.signUp(authCredentialsDto)
}
From what I understand swagger doesn't know how to work with interfaces instead I have to use classes. Is there a simple way to document bad request response triggered by ValidationPipe. This is all native #nestjs behavior so I would assume there must be an easy solution.
This is what gets actually returned from API:
"statusCode": 400,
"error": "Bad Request",
"message": [
{
"target": {
"username": "somename",
"password": "****"
},
"value": "****",
"property": "password",
"children": [], // ValidationError[]
"constraints": {
"matches": "password too weak"
}
}
]
I used this instructions: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_post_messages
I got bearer token and users, but when I try create message using Postman it throw exception
My request:
https://graph.microsoft.com/v1.0/users/4850bf92-08ff-41f3-9891-51561239aaa54/messages
{
"subject":"Did you see last night's game?",
"importance":"Low",
"body":{
"contentType":"HTML",
"content":"They were <b>awesome</b>!"
},
"toRecipients":[
{
"emailAddress":{
"address":"user#mail.com"
}
}
]
}
Response:
{
"error": {
"code": "ResourceNotFound",
"message": "Resource could not be discovered.",
"innerError": {
"request-id": "2b956003-3e1a-4d0d-b5dd-e7f17625e1ac",
"date": "2018-10-04T17:13:57"
}
}
}
Evening All,
I'm hoping that this is me making a school-boy error. Trying to 'get started' with fortuneJS but having an issue whilst trying to create a new resource.
So, I've setup fortune as described on their homepage. I've opted to use their JSON API plugin, again setup as per their repo.
I'm using Postman to test out the server I've created and I can create a 'user' resource no problem with the following:
{
"data": {
"type": "user",
"attributes": {
"name": "Andrew"
}
}
}
That works fine and I get a response as follows:
{
"data": {
"type": "users",
"id": "37446bbc",
"attributes": {
"name": "Andrew"
},
"relationships": {
"posts": {
"links": {
"self": "http://localhost:1337/users/37446bbc/relationships/posts",
"related": "http://localhost:1337/users/37446bbc/posts"
},
"data": []
}
},
"links": {
"self": "http://localhost:1337/users/37446bbc"
}
}
}
Now, I need to try and create the 'post' resource. Following the JSON API specification I'm posting the following payload:
{
"data": {
"type": "posts",
"attributes": {
"message": "This is my first post"
},
"relationships": {
"author": {
"data": { "type": "users", "id": "37446bbc" }
}
}
}
}
All I get back from that is:
{
"errors": [
{
"title": "Error",
"detail": "An internal server error occurred."
}
]
}
I've debugged by placing a console log of the 'error' on line 118 in node_modules/fortune/dist/lib/dispatch/index.js which shows this error:
[TypeError: Cannot set property 'user' of undefined]
Any advice or guidance you can offer would be greatly appreciated. Hopefully it's just me!
I'm using babel-node app.js to get this running. To save you time, I've thrown up the code onto a public repo
It seems that the actual error message needs to be relayed to the client. You can do so by attaching a catch to the HTTP listener:
const server = http.createServer((request, response) =>
fortune.net.http(store)(request, response)
.catch(error => console.log(error.stack)))
What I found when I recreated the steps was this:
Error: A related record for the field "author" was not found.
However, since it is a generic Error and not a typed error that Fortune uses internally, it is hidden from the client.
So by setting the correct value for the author id, it was able to create a record with that association successfully.
Future versions will be patched so that this informative error message gets shown.
The originally posted question works fine, the version of node was causing an error. Upgrading to v4.2.1 resolved the issue.
I'm actually implementing Social sharing in my project, so i am doing google+ sharing. While posting message to Google+ using nodejs,I'm getting 403 forbidden error do i need to configure anything on google+ account so that posted message is seen at google+
var params = { "object": {
"originalContent": "hello"
},
"access": {
"items": [
{
"type": "mycircle"
}
],
"domainRestricted": true
}
};
var headers = {
Authorization: 'Bearer ' + google_access_token
};
request.post(shareApiUrl, {
url: 'https://www.googleapis.com/plusDomains/v1/people/{{userid}}/activities',
headers: headers,
body: params,
json: true
}, function (err, response, body) {
console.log(body)
)}
Error Description:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
For Posting a feed/or message we should have Google Apps account, but it is impossible with regular GMail account, or your Apps admin hasn't enabled Google+ for the Apps domain.