Mule APIKit Include Reason in 400 error - mule

I have a raml doc the specifies my request data structure with a field like the following:
"EstInstallDate": {
"description": "the estimated date that the installation will be completed",
"type": "string",
"format": "date"
}
this is great, because when the APIkit is hit, a MessageException is raise with the following text:
string "2016-32-32" is invalid against requested date format(s)
yyyy-MM-dd
but the generic 400 error payload is jsut "bad request" I would like to include this error message in the response payload.
how do i do this?

I found that in my exception block i can access
exception.message
to get the full string of the error. however, it would be great to include which field failed the validation

Related

Is a good practice return a list of valid values in a Bad Request?

Example: An API endpoint that accepts in a PET field the values "DOG" and "PET". If it receives an request with the payload value with "RABBIT",
{
"animal": "RABBIT"
}
is a good practice return a 400 Bad Request (or even a 422 Unprocessable Entity) with the list of the valid values in the message?
Like "Invalid value for the animal field. Valid values: "DOG" and "CAT"? Or should i just return the http code?
You SHOULD (in the RFC 2119 sense) return a representation that explains the situation.
Except when responding to a HEAD request, the server SHOULD send a representation containing an explanation of the error situation, and whether it is a temporary or permanent condition. These status codes are applicable to any request method. User agents SHOULD display any included representation to the user. -- RFC 7231
HTTP status code 400 is much general than 422. HTTP status code 422 feels like a much more appropriate response for situations where the data is understood, but is still not valid.
Even if you want to return 400 status code, it's correct. In any case, make sure that the error response in body explains what issue is.
HTTP/1.1 422 Unprocessable Entity
{
"message": "Validation Failed",
"errors": [
{
"field": "animal",
"code": "RABBIT is not valid value. Value must be either PET or DOG"
}
]
}

This location is unknown

Today I started getting This location is unknown errors on almost every Flight Offers Search call to the test API. I'm using this data https://github.com/amadeus4dev/data-collection/blob/master/data/flightsearch.md to make requests.
The kind of error that I get is this:
{
"code": 4926,
"title": "INVALID DATA RECEIVED",
"detail": "This location code is unknown",
"status": 400
}
Is there something going on today with test API? On friday everything worked.

Use of Amadeus Trip parser API

UPDATE : Fix one problem with the content-type of the request which has to be application/vnd.amadeus+json 🤷‍♂️ After the fix, lot of mails are not able to be parse without additional details. Amadeus support kind of confirmed me that my test mails are from providers that are not supported :/
I try to use Self-Service Trip Parser API https://developers.amadeus.com/self-service/category/trip/api-doc/trip-parser
I did some testing using confirmation emails from well-known brand like Booking or Oui SNCF but with no success and generally got 500 generic errors.
What I do is :
go to gmail, download the message as .eml format
encode it to base 64 base64 -i mail.eml | tr -d '\n' | pbcopy
create the payload to send to Amadeus using own Amadeus Swagger but got 500 errors in most case
{
"data": {
"type": "trip-parser-job",
"content": "<paste mail content>"
}
}
{
"errors": [
{
"code": "38189",
"title": "Internal error",
"detail": "An internal error occurred, please contact your administrator",
"status": "500"
}
]
}
In best case, the job is created, but the status is failure after a few minutes
Only using mail PDF attachment seems to work sometimes.
My questions are simple :
do any of you make it works reliably ?
is there any additional information on support input format or providers ?
is there any worthwhile alternative ?

Question about testIamPermissions method in Billing API

I'm trying to use cloudbilling.billingAccounts.testIamPermissions in the APIs Explorer, but I get an error.
API URL
https://developers.google.com/apis-explorer/?hl=ko#p/cloudbilling/v1/cloudbilling.billingAccounts.testIamPermissions?resource=billingAccounts%252F01183E-6A3E97-BE2C7A&resource=%257B%250A%257D&_h=1&
Error Result
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT"
}
}
The error message appears as 'Request contains an invalid argument', so the value entered in resource seems to be incorrect.
I entered billingAccounts / {billingAccountID} for resource, but I do not know why I get an error.
{billingAccountID} has entered the billing account ID you are using.
What value should be put in the resource?
You need to use your full ID "billingAccounts/012345-567890-ABCDEF`" as an string. Also avoid to share your private information for security reasons use examples instead.
Confirm that the other options of the API works for you.

Can't create replies to some existing youtube comments

I have a software, which allows you to create a reply to a comment on your youtube video. Therefore I use the youtube API v3 comments.insert method.
POST https://www.googleapis.com/youtube/v3/comments?part=id%2Csnippet&access_token=[access_token]
{
"snippet": {
"parentId": "parentId",
"textOriginal": "test message"
}
}
Most of the time the requests are successful. But for some comments I can't create replies this way. The API always returns:
{
"error": {
"errors": [
{
"domain": "youtube.comment",
"reason": "processingFailure",
"message": "The API server failed to successfully process the request. While this can be a transient error, it usually indicates that the requests input is invalid. Check the structure of the <code>comment</code> resource in the request body to ensure that it is valid.",
"locationType": "other",
"location": "body"
}
],
"code": 400,
"message": "The API server failed to successfully process the request. While this can be a transient error, it usually indicates that the requests input is invalid. Check the structure of the <code>comment</code> resource in the request body to ensure that it is valid."
}
}
I'm using a valid access token and the parentId is valid, too, because I can retrieve it through the API.
I took a look at the successful and failing requests, but didn't find any difference. So I assume that the request input isn't invalid as it is mentioned in the error message.
In my opinion this error isn't a transient error, because the same requests are still failing after some days.
I also tried to create a reply on such a comment through the API Explorer but the result was the same.
Does anyone have the same problems or am I doing something wrong?
When I go to the video and look at the comments directly, the comment with ID z13tjxdqnuygy1lga04cilcqxqipg1zbtbs has a "reply" option under it, while the comment with ID z13rgftjgw3bulyou04ccfnbjofztxg54yo0k does not. It seems that the user posted the comment via their Google+ page and disabled replies to their posts.