I am using graphene_django and I am interested in having custom errors being raised
What I am trying is:
class CustomGraphQLError(GraphQLError):
def __init__(self, message, extensions, nodes=None, source=None, positions=None, path=None, original_error=None):
super().__init__(message, nodes, source, positions, path, original_error, extensions)
and then raising an error like this
raise CustomGraphQLError
Despite I have made extensions mandatory, they don't seem to appear in the response
Example response
{
"errors": [
{
"message": "Custom error",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"traces"
]
}
],
"data": {
"traces": null
}
}
Can't understand whats wrong here
Related
I have created a chatbot in DialogFlow CX. After a customer identifies themselves, a call is made to the webhook (written in Python) which finds the 3 closest retail stores to the customer, and returns those in the webhook response as parameters:
bot_response = {
"fulfillment_response":
{
"messages": [
{
"text": {
"text": [
f'Thanks {first_name}! I\'ve located your account.'
]
}
}
]
},
"session_info": {
"session": session_name,
"parameters": {
"first_name": first_name,
"email_address": email_address,
"business_partner_id": business_partner_id,
"address_line_1": c['response']['address_line_1'],
"address_line_2": c['response']['address_line_2'],
"suburb": c['response']['suburb'],
"postcode": c['response']['postcode'],
"region": c['response']['state'],
"store_1": locations[0].store_name,
"store_1_id": locations[0].store_id,
"store_1_address": locations[0].address,
"store_2": locations[1].store_name,
"store_2_id": locations[1].store_id,
"store_2_address": locations[1].address,
"store_3": locations[2].store_name,
"store_3_id": locations[2].store_id,
"store_3_address": locations[2].address
}
}
}
My intention is to allow the customer to select 1 of these 3 store locations. In the above model, I've returned them as parameters, which are successfully recorded in dialogflow, however I am stuck on how to provide these values as a list of options to the customer. I am unsure whether I can
a) Provide a list of options back to the user as a Webhook Response (instead of parameters). All documentation I can find suggests only that text and parameters can be returned.
Or
b) Use the returned parameters to create a custom payload to present them as a list for the user to select from. Something like:
{
"richContent": [
[
{
"event": {
"name": "Store1",
"parameters": {},
"languageCode": ""
},
"subtitle": "${store_1_id}",
"title": "${store_1_address}",
"type": "list"
}
]
]
}
But I cannot find any documentation to suggest you can embed parameters into custom payloads.
Does anyone know of a way to solve this situation? Thank you!
As per usual, the mere act of posting a question on Stack Overflow somehow creates a higher statistical likelihood that I will in fact answer my own question. It's simple enough to add it to a custom payload to present in a list, simply using the syntax:
{
"richContent": [
[
{
"event": {
"name": "Store1",
"parameters": {},
"languageCode": ""
},
"subtitle": "$session.params.store_1_address",
"title": "Store 1",
"type": "list"
}
]
]
}
After a day of work with Postman, I have managed to reduce the number of errors down to 1. No idea how to get past it.
Definitely not an authorisation problem. I've been making lots of authorised calls.
URI:
POST https://api.ebay.com/sell/account/v1/fulfillment_policy
Body:
{
"categoryTypes": [
{
"name": "ALL_EXCLUDING_MOTORS_VEHICLES"
}
],
"freightShipping": "false",
"globalShipping": "false",
"handlingTime": {
"unit": "DAY",
"value": "1"
},
"localPickup": "true",
"marketplaceId": "EBAY_AU",
"name": "100 grams",
"shippingOptions": [
{
"costType": "CALCULATED",
"optionType": "DOMESTIC",
"shippingServices": [
{
"shippingCarrierCode": "Australia Post",
"shippingServiceCode": "AU_Regular"
}
]
}
]
}
Output:
{
"errors": [
{
"errorId": 20403,
"domain": "API_ACCOUNT",
"category": "REQUEST",
"message": "Invalid .",
"longMessage": "Please select a valid postage service.",
"inputRefIds": [
"service"
],
"parameters": [
{
"name": "XPATH",
"value": "DomesticItemShippingService[0].shippingService"
}
]
}
]
}
Things I've Tried:
Deleting "shippingOptions": [...] (and everything inside the []s) got rid of the errors and resulted in the successful creation of a new fulfillment policy. However, I wanted to include shipping options in my call.
shippingCarrierCode doesn't seem to do anything. I've changed it to all sorts of sensible and non sensible things, including deleting it entirely. No impact on the output.
Changing shippingServiceCode to anything non-standard (eg "shippingServiceCode": "potato") results in getting the exact same error, but twice instead of once. (See below) How can I get the same error twice with only one shipping option?
Including a domestic and international option, I get the same error twice also. (Same output as below, except the second DomesticItemShippingService[1].shippingService is instead DomesticItemShippingService[0].shippingService)
Making an international option AND a domestic option, BOTH with silly service names results in 3 errors. (I was expecting 4.)
Code:
{
"errors": [
{
"errorId": 20403,
"domain": "API_ACCOUNT",
"category": "REQUEST",
"message": "Invalid .",
"longMessage": "Please select a valid postage service.",
"inputRefIds": [
"service"
],
"parameters": [
{
"name": "XPATH",
"value": "DomesticItemShippingService[0].shippingService"
}
]
},
{
"errorId": 20403,
"domain": "API_ACCOUNT",
"category": "REQUEST",
"message": "Invalid .",
"longMessage": "Please select a valid postage service.",
"inputRefIds": [
"service"
],
"parameters": [
{
"name": "XPATH",
"value": "DomesticItemShippingService[1].shippingService"
}
]
}
]
}
What did I do wrong this time?
I did get an answer to my question. Not here, even though I sent them the link here, but I got the answer (eventually) through official eBay channels.
I'll post that answer here for everyone. I was thinking of adding correct stackoverflow formatting, but decided it would be better to leave the correct answer untouched from the original.
Hello Jonathon ,
Ignore my last message and Apologize for the confusion.
Here is the reason why you are getting the error:
You have to set "localPickup": "false", refer doc for your help:
https://developer.ebay.com/api-docs/sell/account/resources/fulfillment_policy/methods/createFulfillmentPolicy#request.localPickup
And you will get response as:
{ "name": "100 grams", "marketplaceId": "EBAY_AU",
"categoryTypes": [
{
"name": "ALL_EXCLUDING_MOTORS_VEHICLES",
"default": true
} ], "handlingTime": {
"value": 1,
"unit": "DAY" }, "shippingOptions": [
{
"optionType": "DOMESTIC",
"costType": "CALCULATED",
"shippingServices": [
{
"sortOrder": 1,
"shippingCarrierCode": "Australia Post",
"shippingServiceCode": "AU_Regular",
"freeShipping": false,
"buyerResponsibleForShipping": false,
"buyerResponsibleForPickup": false
}
],
"insuranceOffered": false,
"insuranceFee": {
"value": "0.0",
"currency": "AUD"
}
} ], "globalShipping": false, "pickupDropOff": false, "freightShipping": false, "fulfillmentPolicyId": "6104871000",
"warnings": [] }
Let us know if you need further assistance!!!
Best Regards, eBay Developer Support
Check them out here. Make sure you have all the required fields.
pickupDropOff
shippingOptions.shippingServices.shipToLocations.regionIncluded
Here is my request body:
server = {
'name': name_gen.haikunate(),
'machineType': f"zones/{zone}/machineTypes/n1-standard-1",
'disks': [
{
'boot': True,
'autoDelete': True,
'initializeParams': {
'sourceImage': 'projects/ubuntu-os-cloud/global/images/ubuntu-1604-xenial-v20191204'
}
}
],
'networkInterfaces': [
{
'network': '/global/networks/default',
'accessConfigs': [
{'type': 'ONE_TO_ONE_NAT', 'name': 'external nat'}
]
}
],
'metadata': {
'items': [
{
'keys': 'startup-script',
'value': startup_script
}
]
}
When using this request body with the compute object to create a vm, it is giving me this error:
googleapiclient.errors.HttpError:
<HttpError 400 when requesting https://compute.googleapis.com/compute/v1/projects/focal-maker-240918/zones/us-east4-c/instances?alt=json
returned "Invalid value for field 'resource.metadata':
'{
"item": [
{
"value": "#!/bin/bash\n\napt-get update\n\nsleep 15\n\nclear\n\napt-get install squ...'. Metadata invalid keys:">'
How can I fix this error?
If we look at the documentation for setting metadata on a Compute Engine instance found here we see that the structure is:
"items": [
{
"key": string,
"value": string
}
],
if we compare that to your structure described in your post, we see you have coded keys instead of key as the field name. This could easily be the issue. To resolve the problem, change keys to key.
I receive JSON Api conform errors from the backend:
{
"errors": [
{
"status": "400",
"source": {
"pointer": "/data/attributes/description"
},
"detail": "This field may not be null."
},
{
"status": "400",
"source": {
"pointer": "/data/attributes/due-date"
},
"detail": "This field may not be null."
},
{
"status": "400",
"source": {
"pointer": "/data/attributes/extra-comments"
},
"detail": "This field may not be null."
},
{
"status": "400",
"source": {
"pointer": "/data/attributes/name"
},
"detail": "This field may not be null."
},
{
"status": "400",
"source": {
"pointer": "/data/attributes/payment-type"
},
"detail": "This field may not be null."
},
{
"status": "400",
"source": {
"pointer": "/data/attributes/price"
},
"detail": "This field may not be null."
}
]
}
I try to show them in my template, as described in the EmberData documentation:
{{#each model.errors.messages as |message|}}
<div class="error">
{{message}}
</div>
{{/each}}
Nothing is shown. I would say the .errors in the model are not populated, but I am not sure how to check this. How can I:
display the received ajax reply?
make sure that EmberData is processing the reply and populating model.errors?
Show the processed model.errors in the console?
Show the model and all properties?
In general, I am experiencing that new versions of Ember are very hard to debug. Whenever I show any Ember object in the console, I just see some Computed properties which are not expanded whenever I try to peek into them.
My backend is:
Django 1.9
with django-rest-framework
django-rest-framework-json-api
EDIT
This is the data that I am POSTing to the backend (JSONAPi conform):
{
"data": {
"attributes": {
"name": null,
"description": null,
"extra-comments": null,
"min-price": 30,
"max-price": 3000,
"price-step": 10,
"price": null,
"payment-type": null,
"due-date": null
},
"relationships": {
"seller": {
"data": null
},
"artist": {
"data": null
},
"subcategory": {
"data": null
}
},
"type": "projects"
}
}
The backend is ok with this, detects the errors, and provides a JSON APi conform errors reply, as specified above.
I think I know what's happening (as it happened to me as well).
Change the HTTP error code from 400 to 422 (Unprocessable Entity) and check if it fixes the problem.
Also, looking at the source code for the JSONAPIAdapter (which extends from the RestAdapter) I think I'm right.
isInvalid: function(status, headers, payload) {
return status === 422;
},
This can be changed to (adapters/application.js):
import DS from 'ember-data';
import config from '../config/environment';
export default DS.JSONAPIAdapter.extend(DataAdapterMixin, {
host: config.API_HOST,
namespace: config.API_NAMESPACE,
isInvalid: function(status, headers, payload) {
return status === 400 || status === 422;
},
});
For reference, I have done this on the django side:
from rest_framework_json_api.exceptions import exception_handler
def custom_exception_handler(exc, context):
# DRF returns 400, but EmberData wants 422. I will force a 422, always.
# Call the rest_framework_json_api's exception handler first,
# to get the standard error response.
response = exception_handler(exc, context)
# TODO: is this correct? 422 in all exception cases?!
response.status_code = 422
return response
Im using the Graph API to get certain data from my managed pages.
What i need is the likes, checkins and talking_about_count from my pages.
When i add checkins and talking_about_count i get an error that the API doesn't know the fields.
So i removed those and only asked for the likes and id.
What the API returns is a list with the posts from the page and only showing the id, creation date and the likes(if there are any).
I tested with some other fields like about and website, but they give the same error as checkins and talking_about_count, so i can't get basic data from my pages..
The link i use is this:
https://graph.facebook.com/168707433219493/feed?access_token=[Access_Token]&fields=id,likes,checkins,talking_about_count
And the error i get:
{
"error": {
"message": "(#100) Unknown fields: checkins,talking_about_count.",
"type": "OAuthException",
"code": 100
}
}
When i only ask for id and likes i get:
{
"data": [
{
"id": "168707433219493_333476503426186",
"created_time": "2012-11-28T19:38:57+0000"
},
{
"id": "168707433219493_370257573064477",
"created_time": "2012-11-22T08:12:11+0000"
},
{
"id": "168707433219493_423778884356339",
"likes": {
"data": [
{
"name": "Guido van Tricht",
"id": "1117357415"
}
],
"count": 1
},
"created_time": "2012-11-19T22:46:01+0000"
}
],
"paging": {
"previous": "https://graph.facebook.com/168707433219493/feed?fields=id,likes&access_token=[Access_Token]&limit=25&since=1354131537&__previous=1",
"next": "https://graph.facebook.com/168707433219493/feed?fields=id,likes&access_token=[Access_Token]&limit=25&until=1350819853"
}
}
I hope someone knows how to solve my problem, thanks in advance.
talking_about_count should be in the /PAGE_ID, not in the feed.
Why not get this data from:
https://graph.facebook.com/168707433219493?access_token=[Access_Token]