Return custom error from appengine behind Google Cloud Endpoints - google-cloud-endpoints

I am using flask and python 3.6 as a backend service that is deployed to App Engine in GCP. This backend is sitting behind Google Cloud Endpoints deployed in Cloud Run. Endpoints takes all my 404 messages and just returns 404 Not Found. I want to send a more informative error message with the 404 code. Is there any way to do so using my current setup? Thanks

You can create a custom 404 html page:
#app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
Then, you need to create 404.html file.

You can use the Python Endpoints library to send HTTP error codes with a custom message as follows:
message = 'No entity with the id "%s" exists.' % entity_id
raise endpoints.NotFoundException(message)
You can find more info in the docs

Related

Gatsby Deployment Issue

I have a javascript file hubspot.js on src/api folder of my gatsby project which become functions automatically with paths based on their file name (according to Gatsby Documentation).
This API is called when submitting one form which should create a contact in hubspot.
When I run the project in development, it successfully returns the response and contact is created. But, while using "serve public" to test in production, it returns:
POST http://localhost:3000/api/hubspot 404 (Not Found)
and also in deploying using nginx configuration, it returns 405 error.
I also have another api function called status which is like this and is a GET api.
export default function handler(req, res) {
res.status(200).json({ status: 'ok' });
}
Even this function is not called and returns not found error.
I don't have any backend as gatsby can handle that part by itself, as described here.
Functions let you build dynamic applications without running servers. Submit forms, authenticate users, securely connect to external services, build GraphQL/REST APIs, and more.
Gatsby Function
So, even in production, this must be handled and the api should be called when the form submits or when I make a GET request to /api/status.
But, all I am getting is 404 not found and 405 error.

Infura and Brownie: HTTPError: 502 Server Error: Bad Gateway for url

I am getting this error every time I try to deploy my smart contract.
HTTPError: 502 Server Error: Bad Gateway for url
It seems Infura requires authentication for API calls as of today. How can I do this using brownie?
To add api_key to your brownie you need to add followings to your .env file created in the root of your project:
export WEB3_INFURA_PROJECT_ID=<your_api_key>
then go to your infura account and create a project then open Manage Key after that copy your key and add it to the line above. To make it available for brwonie to use run line below in terminal :
source .env
Check your code again and let me know if it worked

IBM Conversation API - What should be a endpoint URL and Parameters

I try to access IBM conversation using Postman tool but getting 404 (Resource not found) error.
EndPoint : https://gateway.watsonplatform.net/conversation/api/v1/workspaces/883c7704-02c4-41fc-b8a0-aea1d0325c5a/message?version=2016-09-20
my workspace id = 883c7704-02c4-41fc-b8a0-aea1d0325c5a
Is there anything wrong in endpoint or parameter?.
How to pass version?
Your endpoint looks correct if you're trying to send a message to conversation: https://www.ibm.com/watson/developercloud/conversation/api/v1/?curl#send_message
Try changing the version to the most updated: version=2017-05-26

RStudio & RGoogleAnalytics giving Error: redirect_uri_mismatch

I am trying to connect to google analytics from R through Analytics API. Following is my code.
library(RGoogleAnalytics)
oauth_token <- Auth(client.id = "clientID", client.secret = "clientSecret")
When I run above command it gives me following error in browser
Error: redirect_uri_mismatch
The redirect URI in the request, http://localhost:1410/, does not match the ones authorized for the OAuth client.
I have following settings in google developer console
Authorised JavaScript origins : http://localhost:1410
Authorised redirect URIs: http://localhost:8080/oauth2callback
Please help.
You will need to update your redirect URIs to the same port.
http://localhost:1410/oauth2callback
If that does not work, create a new client secret json file. Use "other" as the application type;

send grid & parse 502 Bad Gateway with nginx

I am trying to migrate my parse application over to digital ocean and followed this guide :
https://www.digitalocean.com/community/tutorials/how-to-migrate-a-parse-app-to-parse-server-on-ubuntu-14-04
Everything works perfectly fine until I get to the very end Test Parse Server ( Executing Example Cloud Code ) section
I tested the cloud code for the sample cloud code that was provided in the tutorial :
Parse.Cloud.define('hello', function(req, res) {
res.success('Hi');
});
so I got a Hi back in my browser as well as in postman.
See image here : https://cloudup.com/cH2dbBx1KTo

Then I test the function that uses sendgrid's service to send emails (http://blog.parse.com/announcements/introducing-the-sendgrid-cloud-module/), my cloud code file looks like this :
see image : https://cloudup.com/cD6MNRP3Tft
and now I try to run my post request from postman and I get an error even on my hello function that was working before
See image : https://cloudup.com/cIkwJ6552_5
So I look around and figure out that its an issue with my sendgrid import
var sendgrid = require("sendgrid");
sendgrid.initialize(“xxxxxx”, “xxxxx.”);
in these lines.
does anyone have any experience with digital ocean cloud code and send grid emailing service please help me out I will be grateful as this is the last step left and I will be done with my migration :)
cheers
Tanzeel
you have to specify server URL in parse config file. It is required and could be the reason why you cant run cloud code.
"PARSE_SERVER_URL": "http://localhost:1337/parse"
The url has be the same what you are using. There is also error in Nginx config in that tutorial, I explained it here https://serverfault.com/questions/765627/cannot-post-get-over-ssl/766428#766428
So I looked up at pm2 and to see real-time logs the command is
pm2 logs
at first when I ran the command I saw some errors, maybe they were there from before :
Then I tried the hello cloud function from postman app to test for its output in pm2 logs and I got the following :
Next I try to run my sendMail sendgrid function and I find out the the api-key I had used in my sendgrid function was throwing an error
ReferenceError: XXXXXXXXXXXX is not defined
So I went back to my cloud code and used quotes around my api-key parameter and passed it as a string in my send grid initialize function. Then I retry and get
[Error: The provided authorization grant is invalid, expired, or revoked]
So I went back to my sendgrid account and made sure that the api-key I was using was the correct one and it seemed to be just fine. I tested again and got the same error again so I decided to generate a new api-key just in case.
So I realize that I was not using the api-key but instead API KEY ID :
When we create a new api-key on sendgrid they give us the actual api key once and they ask us to store it in some secure place :
We can only display the key above one time. Please store it somewhere safe because as soon as you navigate away from this page, we will not be able to retrieve or restore this generated token.
So after I used an actual api-key I was able to send emails 😃
But one small issue still remains and I am not sure if its because of postman that I am using to run cloud code or something in the parse server or nginx that is still returning me with a 502 Bad Gateway as a response
But when I look at the logs for my parse server I do see a
parse-wrapper-0 { message: 'success' }
but it never gets back to me in my postman and instead I am getting a 502 error not sure why but the emails are being sent succesfully :)

Resources