apache/airflow-client-go

Request.Execute() return `undefined response type` error

zbysir opened this issue · 4 comments

➜  ~ curl -i -X GET 'https://airflow.xxx.com/api/v1/dags/xx/dagRuns/xxx' \
-H 'Content-Type: application/json' -H 'Accept: application/json' \
--user "xxx:xxx" \
-d '{}'
HTTP/2 404
date: Wed, 01 Feb 2023 07:42:55 GMT
content-type: application/problem+json
content-length: 263
server: gunicorn
x-robots-tag: noindex, nofollow

{
  "detail": "DAGRun with DAG ID: 'xxx' and DagRun ID: 'xxx' not found",
  "status": 404,
  "title": "DAGRun not found",
  "type": "https://airflow.apache.org/docs/apache-airflow/2.5.0/stable-rest-api-ref.html#section/Errors/NotFound"
}

In airflow version 2.5.0, Content-type header in error response is application/problem+json, but in this repo the json content-type is check by regexp

jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`)

The regexp can't match application/problem+json, I guess that's the problem.

About problem+json

I found a related issue in openapi-generator:

OpenAPITools/openapi-generator#4890

Amazingly surprised that this was a three year old question and it wasn't closed.

Hello @zbysir,

Thank you for reporting this, indeed it looks like the problem+json content type is not handled by generated clients. We could also add a post generation step to update the accepted content type for the client. I just opened a PR for that.

In the mean time, the nethttp.Response returned object will have everything you need from that failed call, maybe this is the reason this issue wasn't addressed yet.

    run, response, error := cli.DAGRunApi.GetDagRun(ctx, "fake", "fake_run").Execute()

In case of an error you need to use 'response' and disregard 'error' which will not be relevant (undefined response type).

PR has been merged, changes will take effect at the next client release.

Thanks.

Thank you for your proposal, it makes sense.

Hello @zbysir,

Thank you for reporting this, indeed it looks like the problem+json content type is not handled by generated clients. We could also add a post generation step to update the accepted content type for the client. I just opened a PR for that.

In the mean time, the nethttp.Response returned object will have everything you need from that failed call, maybe this is the reason this issue wasn't addressed yet.

    run, response, error := cli.DAGRunApi.GetDagRun(ctx, "fake", "fake_run").Execute()

In case of an error you need to use 'response' and disregard 'error' which will not be relevant (undefined response type).