From e5894ee96418f74cbd398ab8d43ccd08fb61277e Mon Sep 17 00:00:00 2001 From: speakeasybot Date: Mon, 7 Jul 2025 23:20:16 +0000 Subject: [PATCH 1/2] ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.576.1 --- .speakeasy/gen.lock | 28 +- .speakeasy/gen.yaml | 3 +- .speakeasy/glean-merged-spec.yaml | 26 +- .speakeasy/workflow.lock | 14 +- RELEASES.md | 12 +- docs/models/answer.md | 52 +-- docs/models/answercreationdata.md | 28 +- docs/models/editanswerrequest.md | 34 +- docs/models/feedrequestcategory.md | 1 + docs/models/listentitiesrequest.md | 3 +- docs/models/message.md | 8 +- docs/models/relation.md | 6 +- docs/models/relationtype.md | 13 +- docs/models/requesttype.md | 11 + docs/models/timeperiodtype.md | 13 +- docs/models/timerange.md | 9 +- docs/models/warningtype.md | 17 +- docs/sdks/agents/README.md | 12 +- docs/sdks/answers/README.md | 36 +- docs/sdks/entities/README.md | 5 +- pyproject.toml | 2 +- speakeasyusagegen/.speakeasy/logs/naming.log | 3 +- src/glean/api_client/_version.py | 6 +- src/glean/api_client/agents.py | 206 +++------ src/glean/api_client/announcements.py | 122 ++---- src/glean/api_client/answers.py | 210 +++------ src/glean/api_client/basesdk.py | 8 +- src/glean/api_client/client_activity.py | 76 +--- src/glean/api_client/client_authentication.py | 42 +- src/glean/api_client/client_chat.py | 372 ++++------------ src/glean/api_client/client_documents.py | 160 ++----- src/glean/api_client/client_shortcuts.py | 198 +++------ src/glean/api_client/client_verification.py | 126 ++---- src/glean/api_client/collections.py | 360 +++++----------- src/glean/api_client/datasources.py | 76 +--- src/glean/api_client/entities.py | 94 ++-- src/glean/api_client/errors/__init__.py | 9 + .../api_client/errors/collectionerror.py | 18 +- src/glean/api_client/errors/gleanbaseerror.py | 26 ++ src/glean/api_client/errors/gleandataerror.py | 17 +- src/glean/api_client/errors/gleanerror.py | 44 +- .../api_client/errors/no_response_error.py | 13 + .../errors/responsevalidationerror.py | 25 ++ .../api_client/indexing_authentication.py | 42 +- src/glean/api_client/indexing_datasource.py | 42 +- src/glean/api_client/indexing_documents.py | 376 ++++------------ src/glean/api_client/indexing_permissions.py | 408 ++++-------------- src/glean/api_client/indexing_shortcuts.py | 76 +--- src/glean/api_client/insights.py | 38 +- src/glean/api_client/messages.py | 42 +- src/glean/api_client/models/__init__.py | 3 + src/glean/api_client/models/answer.py | 12 +- .../api_client/models/answercreationdata.py | 12 +- .../api_client/models/editanswerrequest.py | 12 +- .../api_client/models/facetfiltervalue.py | 1 + src/glean/api_client/models/feedrequest.py | 1 + src/glean/api_client/models/inputoptions.py | 1 + .../api_client/models/listentitiesrequest.py | 14 + .../api_client/models/relateddocuments.py | 6 +- src/glean/api_client/models/searchwarning.py | 1 + src/glean/api_client/models/timerange.py | 7 + src/glean/api_client/people.py | 350 ++++----------- src/glean/api_client/pins.py | 206 +++------ src/glean/api_client/policies.py | 198 +++------ src/glean/api_client/reports.py | 114 ++--- src/glean/api_client/search.py | 214 +++------ src/glean/api_client/tools.py | 84 +--- src/glean/api_client/utils/__init__.py | 3 + src/glean/api_client/utils/serializers.py | 24 +- src/glean/api_client/visibilityoverrides.py | 84 +--- .../internal/sdk/models/components/answer.go | 4 +- .../models/components/answercreationdata.go | 4 +- .../models/components/editanswerrequest.go | 4 +- .../sdk/models/components/facetfiltervalue.go | 11 +- .../sdk/models/components/feedrequest.go | 3 + .../sdk/models/components/inputoptions.go | 11 +- .../models/components/listentitiesrequest.go | 36 ++ .../sdk/models/components/relateddocuments.go | 10 +- .../sdk/models/components/searchwarning.go | 15 +- .../sdk/models/components/timerange.go | 9 + tests/test_entities.py | 1 + 81 files changed, 1500 insertions(+), 3523 deletions(-) create mode 100644 docs/models/requesttype.md create mode 100644 src/glean/api_client/errors/gleanbaseerror.py create mode 100644 src/glean/api_client/errors/no_response_error.py create mode 100644 src/glean/api_client/errors/responsevalidationerror.py diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 2c2fd080..802a481b 100644 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: 3e3290ca-0ee8-4981-b1bc-14536048fa63 management: - docChecksum: 6cb4c4786bf30fecfc20b38750d745eb + docChecksum: bb65a174a6b697994f7bde3845843d9d docVersion: 0.9.0 - speakeasyVersion: 1.563.1 - generationVersion: 2.629.1 - releaseVersion: 0.6.6 - configChecksum: deb305dde9c116c694b15d39c5ae7854 + speakeasyVersion: 1.576.1 + generationVersion: 2.651.2 + releaseVersion: 0.7.0 + configChecksum: 1fdd57721d8451c79856369d08e3d61d repoURL: https://github.com/gleanwork/api-client-python.git installationURL: https://github.com/gleanwork/api-client-python.git published: true @@ -16,7 +16,7 @@ features: additionalProperties: 1.0.1 configurableModuleName: 0.2.0 constsAndDefaults: 1.0.5 - core: 5.19.3 + core: 5.19.4 defaultEnabledRetries: 0.2.0 deprecations: 3.0.2 devContainers: 3.0.0 @@ -31,13 +31,13 @@ features: globalServerURLs: 3.1.1 groups: 3.0.0 methodArguments: 1.0.2 - mockServer: 0.1.0 + mockServer: 0.1.1 multipartFileContentType: 1.0.0 nameOverrides: 3.0.1 responseFormat: 1.0.1 retries: 3.0.2 sdkHooks: 1.1.0 - tests: 1.17.0 + tests: 1.19.1 unions: 3.0.4 uploadStreams: 1.0.0 generatedFiles: @@ -481,6 +481,7 @@ generatedFiles: - docs/models/reminderrequest.md - docs/models/reportstatusresponse.md - docs/models/reportstatusresponsestatus.md + - docs/models/requesttype.md - docs/models/responsehint.md - docs/models/responsestatus.md - docs/models/restrictionfilters.md @@ -663,8 +664,11 @@ generatedFiles: - src/glean/api_client/entities.py - src/glean/api_client/errors/__init__.py - src/glean/api_client/errors/collectionerror.py + - src/glean/api_client/errors/gleanbaseerror.py - src/glean/api_client/errors/gleandataerror.py - src/glean/api_client/errors/gleanerror.py + - src/glean/api_client/errors/no_response_error.py + - src/glean/api_client/errors/responsevalidationerror.py - src/glean/api_client/governance.py - src/glean/api_client/governance_documents.py - src/glean/api_client/httpclient.py @@ -2012,17 +2016,17 @@ examples: createAndStreamRun: speakeasy-default-create-and-stream-run: requestBody: - application/json: {"agent_id": ""} + application/json: {"agent_id": "", "messages": [{"role": "USER"}]} responses: "200": text/event-stream: "" createAndWaitRun: speakeasy-default-create-and-wait-run: requestBody: - application/json: {"agent_id": ""} + application/json: {"agent_id": "", "messages": [{"role": "USER"}]} responses: "200": - application/json: {} + application/json: {"run": {"agent_id": "", "messages": [{"role": "USER"}]}, "messages": [{"role": "USER"}]} addcollectionitems: speakeasy-default-addcollectionitems: requestBody: @@ -2197,7 +2201,7 @@ examples: listentities: speakeasy-default-listentities: requestBody: - application/json: {"filter": [{"fieldName": "type", "values": [{"value": "Spreadsheet", "relationType": "EQUALS"}, {"value": "Presentation", "relationType": "EQUALS"}]}], "entityType": "PEOPLE", "pageSize": 100} + application/json: {"filter": [{"fieldName": "type", "values": [{"value": "Spreadsheet", "relationType": "EQUALS"}, {"value": "Presentation", "relationType": "EQUALS"}]}], "entityType": "PEOPLE", "pageSize": 100, "requestType": "STANDARD"} responses: "200": application/json: {"results": [{"name": "George Clooney", "obfuscatedId": "abc123"}], "teamResults": [{"id": "", "name": "", "members": [{"person": {"name": "George Clooney", "obfuscatedId": "abc123"}, "relationship": "MEMBER"}], "customFields": [{"label": "", "values": [], "displayable": true}], "datasourceProfiles": [{"datasource": "github", "handle": ""}], "status": "PROCESSED", "canBeDeleted": true}], "customEntityResults": [{"roles": [{"person": {"name": "George Clooney", "obfuscatedId": "abc123"}, "role": "OWNER"}]}], "facetResults": [{"sourceName": "container_name", "operatorName": "SelectMultiple", "buckets": [{"count": 1, "datasource": "jira", "percentage": 5, "value": {"stringValue": "engineering", "integerValue": 5, "displayLabel": "engineering", "iconConfig": {"color": "#343CED", "key": "person_icon", "iconType": "GLYPH", "name": "user"}}}], "hasMoreBuckets": false, "groupName": "Service Cloud"}]} diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index 24d33d1b..560dc1d8 100644 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -22,10 +22,11 @@ generation: mockServer: disabled: false tests: + generateTests: true generateNewTests: true skipResponseBodyAssertions: true python: - version: 0.6.6 + version: 0.7.0 additionalDependencies: dev: {} main: {} diff --git a/.speakeasy/glean-merged-spec.yaml b/.speakeasy/glean-merged-spec.yaml index 04a2a3cc..e41f9253 100644 --- a/.speakeasy/glean-merged-spec.yaml +++ b/.speakeasy/glean-merged-spec.yaml @@ -1795,7 +1795,7 @@ paths: tags: - Entities summary: List entities - description: List some set of details for all entities that fit the given criteria and return in the requested order. Does not support negation in filters, assumes relation type EQUALS. There is a limit of 10000 entities that can be retrieved via this endpoint. + description: List some set of details for all entities that fit the given criteria and return in the requested order. Does not support negation in filters, assumes relation type EQUALS. There is a limit of 10000 entities that can be retrieved via this endpoint, except when using FULL_DIRECTORY request type for people entities. operationId: listentities x-visibility: Public x-codegen-request-body-name: payload @@ -4122,6 +4122,7 @@ components: - ID_EQUALS - LT - GT + - NOT_EQUALS example: EQUALS isNegated: type: boolean @@ -4868,7 +4869,8 @@ components: example: From https://en.wikipedia.org/wiki/Diffuse_sky_radiation, the sky is blue because blue light is more strongly scattered than longer-wavelength light. boardId: type: integer - description: The parent board ID of this Answer, or 0 if it's a floating Answer. + description: The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted. + deprecated: true audienceFilters: type: array description: Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search. @@ -5640,11 +5642,13 @@ components: - ATTACHMENT - CANONICAL - CASE + - contact - CONTACT - CONVERSATION_MESSAGES - EXPERT - FROM - HIGHLIGHT + - opportunity - OPPORTUNITY - RECENT - SOURCE @@ -7523,6 +7527,7 @@ components: type: string title: Role description: The role of the message. + example: USER content: title: Content description: The content of the message. @@ -8415,6 +8420,7 @@ components: - COPYPASTED_QUOTES - INVALID_OPERATOR - MAYBE_INVALID_FACET_QUERY + - TOO_MANY_DATASOURCE_GROUPS description: The type of the warning. lastUsedTerm: type: string @@ -9058,6 +9064,7 @@ components: - DISPLAYABLE_LIST - SOCIAL_LINK - EXTERNAL_TASKS + - WORKFLOW_COLLECTIONS - ZERO_STATE_CHAT_SUGGESTION - ZERO_STATE_CHAT_TOOL_SUGGESTION - ZERO_STATE_WORKFLOW_CREATED_BY_ME @@ -9632,6 +9639,16 @@ components: source: type: string description: A string denoting the search surface from which the endpoint is called. + requestType: + type: string + default: STANDARD + description: The type of request being made. + x-enumDescriptions: + STANDARD: Used by default for all requests and satisfies all standard use cases for list requests. Limited to 10000 entities. + FULL_DIRECTORY: Used exclusively to return a comprehensive list of all people entities in the organization, typically for audit like purposes. The recommended approach is to sort by FIRST_NAME or LAST_NAME, and use pagination for large organizations. + enum: + - STANDARD + - FULL_DIRECTORY EntitiesSortOrder: type: string description: Different ways of sorting entities @@ -11745,6 +11762,10 @@ components: type: string description: end time of the time range, applicable for the CUSTOM type. format: date-time + lastNDaysValue: + type: integer + description: The number of days to look back from the current time, applicable for the LAST_N_DAYS type. + format: int64 InputOptions: description: Controls which data-sources and what time-range to include in scans. properties: @@ -11779,6 +11800,7 @@ components: - PAST_YEAR - PAST_DAY - CUSTOM + - LAST_N_DAYS customTimeRange: $ref: "#/components/schemas/TimeRange" SharingOptions: diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index 7763e349..1bb9da22 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,12 +1,12 @@ -speakeasyVersion: 1.563.1 +speakeasyVersion: 1.576.1 sources: Glean API: sourceNamespace: glean-api-specs - sourceRevisionDigest: sha256:766f374184dd7d6b119aef718a826e26e7e690a65bd8edd8e326c75699c9c0f5 - sourceBlobDigest: sha256:b566588e295fa760c08dc3e5f61f4026e3b295999709bbec5a3f434f51316f89 + sourceRevisionDigest: sha256:57fc6af98e6e9e98c92547985293be8fafd52d2a1d1ef88d4b24636743b9f119 + sourceBlobDigest: sha256:01cf4577ff2f15ba160b16bba410571a8ba0c5fefa7e6dd7101edef7ef7c68dc tags: - latest - - speakeasy-sdk-regen-1749670145 + - speakeasy-sdk-regen-1750453704 Glean Client API: sourceNamespace: glean-client-api sourceRevisionDigest: sha256:4edc63ad559e4f2c9fb9ebf5edaaaaa9269f1874d271cfd84b441d6dacac43d2 @@ -17,10 +17,10 @@ targets: glean: source: Glean API sourceNamespace: glean-api-specs - sourceRevisionDigest: sha256:766f374184dd7d6b119aef718a826e26e7e690a65bd8edd8e326c75699c9c0f5 - sourceBlobDigest: sha256:b566588e295fa760c08dc3e5f61f4026e3b295999709bbec5a3f434f51316f89 + sourceRevisionDigest: sha256:57fc6af98e6e9e98c92547985293be8fafd52d2a1d1ef88d4b24636743b9f119 + sourceBlobDigest: sha256:01cf4577ff2f15ba160b16bba410571a8ba0c5fefa7e6dd7101edef7ef7c68dc codeSamplesNamespace: glean-api-specs-python-code-samples - codeSamplesRevisionDigest: sha256:6fc7a331ac2723e7e15b995ac16fcbcb8e5e23c00dba76053d4977ed1b7ea737 + codeSamplesRevisionDigest: sha256:a3e4747f03210d3a8c89a108ea025873dc27315afa1bc443db740a904074c96e workflow: workflowVersion: 1.0.0 speakeasyVersion: latest diff --git a/RELEASES.md b/RELEASES.md index 73bc2803..65fccb8e 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -168,4 +168,14 @@ Based on: ### Generated - [python v0.6.6] . ### Releases -- [PyPI v0.6.6] https://pypi.org/project/glean/0.6.6 - . \ No newline at end of file +- [PyPI v0.6.6] https://pypi.org/project/glean/0.6.6 - . + +## 2025-07-07 23:17:03 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.576.1 (2.651.2) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v0.7.0] . +### Releases +- [PyPI v0.7.0] https://pypi.org/project/glean/0.7.0 - . \ No newline at end of file diff --git a/docs/models/answer.md b/docs/models/answer.md index b7ee7ee7..1bb86be7 100644 --- a/docs/models/answer.md +++ b/docs/models/answer.md @@ -3,29 +3,29 @@ ## Fields -| Field | Type | Required | Description | Example | -| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `id` | *int* | :heavy_check_mark: | The opaque ID of the Answer. | 3 | -| `doc_id` | *Optional[str]* | :heavy_minus_sign: | Glean Document ID of the Answer. The Glean Document ID is supported for cases where the Answer ID isn't available. If both are available, using the Answer ID is preferred. | ANSWERS_answer_3 | -| `question` | *Optional[str]* | :heavy_minus_sign: | N/A | Why is the sky blue? | -| `question_variations` | List[*str*] | :heavy_minus_sign: | Additional ways of phrasing this question. | | -| `body_text` | *Optional[str]* | :heavy_minus_sign: | The plain text answer to the question. | From https://en.wikipedia.org/wiki/Diffuse_sky_radiation, the sky is blue because blue light is more strongly scattered than longer-wavelength light. | -| `board_id` | *Optional[int]* | :heavy_minus_sign: | The parent board ID of this Answer, or 0 if it's a floating Answer. | | -| `audience_filters` | List[[models.FacetFilter](../models/facetfilter.md)] | :heavy_minus_sign: | Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search. | | -| `added_roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer added by the owner. | | -| `removed_roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer removed by the owner. | | -| `roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of roles for this answer explicitly granted by an owner, editor, or admin. | | -| `source_document_spec` | [Optional[models.DocumentSpecUnion]](../models/documentspecunion.md) | :heavy_minus_sign: | N/A | | -| `source_type` | [Optional[models.AnswerSourceType]](../models/answersourcetype.md) | :heavy_minus_sign: | N/A | | -| `permissions` | [Optional[models.ObjectPermissions]](../models/objectpermissions.md) | :heavy_minus_sign: | N/A | | -| `combined_answer_text` | [Optional[models.StructuredText]](../models/structuredtext.md) | :heavy_minus_sign: | N/A | | -| `likes` | [Optional[models.AnswerLikes]](../models/answerlikes.md) | :heavy_minus_sign: | N/A | | -| `author` | [Optional[models.Person]](../models/person.md) | :heavy_minus_sign: | N/A | {
"name": "George Clooney",
"obfuscatedId": "abc123"
} | -| `create_time` | [date](https://docs.python.org/3/library/datetime.html#date-objects) | :heavy_minus_sign: | The time the answer was created in ISO format (ISO 8601). | | -| `update_time` | [date](https://docs.python.org/3/library/datetime.html#date-objects) | :heavy_minus_sign: | The time the answer was last updated in ISO format (ISO 8601). | | -| `updated_by` | [Optional[models.Person]](../models/person.md) | :heavy_minus_sign: | N/A | {
"name": "George Clooney",
"obfuscatedId": "abc123"
} | -| `verification` | [Optional[models.Verification]](../models/verification.md) | :heavy_minus_sign: | N/A | | -| `board` | [Optional[models.AnswerBoard]](../models/answerboard.md) | :heavy_minus_sign: | N/A | | -| `collections` | List[[models.Collection](../models/collection.md)] | :heavy_minus_sign: | The collections to which the answer belongs. | | -| `document_category` | *Optional[str]* | :heavy_minus_sign: | The document's document_category(.proto). | | -| `source_document` | [Optional[models.Document]](../models/document.md) | :heavy_minus_sign: | N/A | | \ No newline at end of file +| Field | Type | Required | Description | Example | +| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `id` | *int* | :heavy_check_mark: | The opaque ID of the Answer. | 3 | +| `doc_id` | *Optional[str]* | :heavy_minus_sign: | Glean Document ID of the Answer. The Glean Document ID is supported for cases where the Answer ID isn't available. If both are available, using the Answer ID is preferred. | ANSWERS_answer_3 | +| `question` | *Optional[str]* | :heavy_minus_sign: | N/A | Why is the sky blue? | +| `question_variations` | List[*str*] | :heavy_minus_sign: | Additional ways of phrasing this question. | | +| `body_text` | *Optional[str]* | :heavy_minus_sign: | The plain text answer to the question. | From https://en.wikipedia.org/wiki/Diffuse_sky_radiation, the sky is blue because blue light is more strongly scattered than longer-wavelength light. | +| ~~`board_id`~~ | *Optional[int]* | :heavy_minus_sign: | : warning: ** DEPRECATED **: This will be removed in a future release, please migrate away from it as soon as possible.

The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted. | | +| `audience_filters` | List[[models.FacetFilter](../models/facetfilter.md)] | :heavy_minus_sign: | Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search. | | +| `added_roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer added by the owner. | | +| `removed_roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer removed by the owner. | | +| `roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of roles for this answer explicitly granted by an owner, editor, or admin. | | +| `source_document_spec` | [Optional[models.DocumentSpecUnion]](../models/documentspecunion.md) | :heavy_minus_sign: | N/A | | +| `source_type` | [Optional[models.AnswerSourceType]](../models/answersourcetype.md) | :heavy_minus_sign: | N/A | | +| `permissions` | [Optional[models.ObjectPermissions]](../models/objectpermissions.md) | :heavy_minus_sign: | N/A | | +| `combined_answer_text` | [Optional[models.StructuredText]](../models/structuredtext.md) | :heavy_minus_sign: | N/A | | +| `likes` | [Optional[models.AnswerLikes]](../models/answerlikes.md) | :heavy_minus_sign: | N/A | | +| `author` | [Optional[models.Person]](../models/person.md) | :heavy_minus_sign: | N/A | {
"name": "George Clooney",
"obfuscatedId": "abc123"
} | +| `create_time` | [date](https://docs.python.org/3/library/datetime.html#date-objects) | :heavy_minus_sign: | The time the answer was created in ISO format (ISO 8601). | | +| `update_time` | [date](https://docs.python.org/3/library/datetime.html#date-objects) | :heavy_minus_sign: | The time the answer was last updated in ISO format (ISO 8601). | | +| `updated_by` | [Optional[models.Person]](../models/person.md) | :heavy_minus_sign: | N/A | {
"name": "George Clooney",
"obfuscatedId": "abc123"
} | +| `verification` | [Optional[models.Verification]](../models/verification.md) | :heavy_minus_sign: | N/A | | +| `board` | [Optional[models.AnswerBoard]](../models/answerboard.md) | :heavy_minus_sign: | N/A | | +| `collections` | List[[models.Collection](../models/collection.md)] | :heavy_minus_sign: | The collections to which the answer belongs. | | +| `document_category` | *Optional[str]* | :heavy_minus_sign: | The document's document_category(.proto). | | +| `source_document` | [Optional[models.Document]](../models/document.md) | :heavy_minus_sign: | N/A | | \ No newline at end of file diff --git a/docs/models/answercreationdata.md b/docs/models/answercreationdata.md index 9f60ecb8..d373c0f9 100644 --- a/docs/models/answercreationdata.md +++ b/docs/models/answercreationdata.md @@ -3,17 +3,17 @@ ## Fields -| Field | Type | Required | Description | Example | -| ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | -| `question` | *Optional[str]* | :heavy_minus_sign: | N/A | Why is the sky blue? | -| `question_variations` | List[*str*] | :heavy_minus_sign: | Additional ways of phrasing this question. | | -| `body_text` | *Optional[str]* | :heavy_minus_sign: | The plain text answer to the question. | From https://en.wikipedia.org/wiki/Diffuse_sky_radiation, the sky is blue because blue light is more strongly scattered than longer-wavelength light. | -| `board_id` | *Optional[int]* | :heavy_minus_sign: | The parent board ID of this Answer, or 0 if it's a floating Answer. | | -| `audience_filters` | List[[models.FacetFilter](../models/facetfilter.md)] | :heavy_minus_sign: | Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search. | | -| `added_roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer added by the owner. | | -| `removed_roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer removed by the owner. | | -| `roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of roles for this answer explicitly granted by an owner, editor, or admin. | | -| `source_document_spec` | [Optional[models.DocumentSpecUnion]](../models/documentspecunion.md) | :heavy_minus_sign: | N/A | | -| `source_type` | [Optional[models.AnswerCreationDataSourceType]](../models/answercreationdatasourcetype.md) | :heavy_minus_sign: | N/A | | -| `added_collections` | List[*int*] | :heavy_minus_sign: | IDs of Collections to which a document is added. | | -| `combined_answer_text` | [Optional[models.StructuredTextMutableProperties]](../models/structuredtextmutableproperties.md) | :heavy_minus_sign: | N/A | | \ No newline at end of file +| Field | Type | Required | Description | Example | +| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `question` | *Optional[str]* | :heavy_minus_sign: | N/A | Why is the sky blue? | +| `question_variations` | List[*str*] | :heavy_minus_sign: | Additional ways of phrasing this question. | | +| `body_text` | *Optional[str]* | :heavy_minus_sign: | The plain text answer to the question. | From https://en.wikipedia.org/wiki/Diffuse_sky_radiation, the sky is blue because blue light is more strongly scattered than longer-wavelength light. | +| ~~`board_id`~~ | *Optional[int]* | :heavy_minus_sign: | : warning: ** DEPRECATED **: This will be removed in a future release, please migrate away from it as soon as possible.

The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted. | | +| `audience_filters` | List[[models.FacetFilter](../models/facetfilter.md)] | :heavy_minus_sign: | Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search. | | +| `added_roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer added by the owner. | | +| `removed_roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer removed by the owner. | | +| `roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of roles for this answer explicitly granted by an owner, editor, or admin. | | +| `source_document_spec` | [Optional[models.DocumentSpecUnion]](../models/documentspecunion.md) | :heavy_minus_sign: | N/A | | +| `source_type` | [Optional[models.AnswerCreationDataSourceType]](../models/answercreationdatasourcetype.md) | :heavy_minus_sign: | N/A | | +| `added_collections` | List[*int*] | :heavy_minus_sign: | IDs of Collections to which a document is added. | | +| `combined_answer_text` | [Optional[models.StructuredTextMutableProperties]](../models/structuredtextmutableproperties.md) | :heavy_minus_sign: | N/A | | \ No newline at end of file diff --git a/docs/models/editanswerrequest.md b/docs/models/editanswerrequest.md index 7b66f4f9..36f51e20 100644 --- a/docs/models/editanswerrequest.md +++ b/docs/models/editanswerrequest.md @@ -3,20 +3,20 @@ ## Fields -| Field | Type | Required | Description | Example | -| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `id` | *int* | :heavy_check_mark: | The opaque ID of the Answer. | 3 | -| `doc_id` | *Optional[str]* | :heavy_minus_sign: | Glean Document ID of the Answer. The Glean Document ID is supported for cases where the Answer ID isn't available. If both are available, using the Answer ID is preferred. | ANSWERS_answer_3 | -| `question` | *Optional[str]* | :heavy_minus_sign: | N/A | Why is the sky blue? | -| `question_variations` | List[*str*] | :heavy_minus_sign: | Additional ways of phrasing this question. | | -| `body_text` | *Optional[str]* | :heavy_minus_sign: | The plain text answer to the question. | From https://en.wikipedia.org/wiki/Diffuse_sky_radiation, the sky is blue because blue light is more strongly scattered than longer-wavelength light. | -| `board_id` | *Optional[int]* | :heavy_minus_sign: | The parent board ID of this Answer, or 0 if it's a floating Answer. | | -| `audience_filters` | List[[models.FacetFilter](../models/facetfilter.md)] | :heavy_minus_sign: | Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search. | | -| `added_roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer added by the owner. | | -| `removed_roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer removed by the owner. | | -| `roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of roles for this answer explicitly granted by an owner, editor, or admin. | | -| `source_document_spec` | [Optional[models.DocumentSpecUnion]](../models/documentspecunion.md) | :heavy_minus_sign: | N/A | | -| `source_type` | [Optional[models.EditAnswerRequestSourceType]](../models/editanswerrequestsourcetype.md) | :heavy_minus_sign: | N/A | | -| `added_collections` | List[*int*] | :heavy_minus_sign: | IDs of Collections to which a document is added. | | -| `removed_collections` | List[*int*] | :heavy_minus_sign: | IDs of Collections from which a document is removed. | | -| `combined_answer_text` | [Optional[models.StructuredTextMutableProperties]](../models/structuredtextmutableproperties.md) | :heavy_minus_sign: | N/A | | \ No newline at end of file +| Field | Type | Required | Description | Example | +| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `id` | *int* | :heavy_check_mark: | The opaque ID of the Answer. | 3 | +| `doc_id` | *Optional[str]* | :heavy_minus_sign: | Glean Document ID of the Answer. The Glean Document ID is supported for cases where the Answer ID isn't available. If both are available, using the Answer ID is preferred. | ANSWERS_answer_3 | +| `question` | *Optional[str]* | :heavy_minus_sign: | N/A | Why is the sky blue? | +| `question_variations` | List[*str*] | :heavy_minus_sign: | Additional ways of phrasing this question. | | +| `body_text` | *Optional[str]* | :heavy_minus_sign: | The plain text answer to the question. | From https://en.wikipedia.org/wiki/Diffuse_sky_radiation, the sky is blue because blue light is more strongly scattered than longer-wavelength light. | +| ~~`board_id`~~ | *Optional[int]* | :heavy_minus_sign: | : warning: ** DEPRECATED **: This will be removed in a future release, please migrate away from it as soon as possible.

The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted. | | +| `audience_filters` | List[[models.FacetFilter](../models/facetfilter.md)] | :heavy_minus_sign: | Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search. | | +| `added_roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer added by the owner. | | +| `removed_roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer removed by the owner. | | +| `roles` | List[[models.UserRoleSpecification](../models/userrolespecification.md)] | :heavy_minus_sign: | A list of roles for this answer explicitly granted by an owner, editor, or admin. | | +| `source_document_spec` | [Optional[models.DocumentSpecUnion]](../models/documentspecunion.md) | :heavy_minus_sign: | N/A | | +| `source_type` | [Optional[models.EditAnswerRequestSourceType]](../models/editanswerrequestsourcetype.md) | :heavy_minus_sign: | N/A | | +| `added_collections` | List[*int*] | :heavy_minus_sign: | IDs of Collections to which a document is added. | | +| `removed_collections` | List[*int*] | :heavy_minus_sign: | IDs of Collections from which a document is removed. | | +| `combined_answer_text` | [Optional[models.StructuredTextMutableProperties]](../models/structuredtextmutableproperties.md) | :heavy_minus_sign: | N/A | | \ No newline at end of file diff --git a/docs/models/feedrequestcategory.md b/docs/models/feedrequestcategory.md index 4212ab55..f651bbb3 100644 --- a/docs/models/feedrequestcategory.md +++ b/docs/models/feedrequestcategory.md @@ -20,6 +20,7 @@ | `DISPLAYABLE_LIST` | DISPLAYABLE_LIST | | `SOCIAL_LINK` | SOCIAL_LINK | | `EXTERNAL_TASKS` | EXTERNAL_TASKS | +| `WORKFLOW_COLLECTIONS` | WORKFLOW_COLLECTIONS | | `ZERO_STATE_CHAT_SUGGESTION` | ZERO_STATE_CHAT_SUGGESTION | | `ZERO_STATE_CHAT_TOOL_SUGGESTION` | ZERO_STATE_CHAT_TOOL_SUGGESTION | | `ZERO_STATE_WORKFLOW_CREATED_BY_ME` | ZERO_STATE_WORKFLOW_CREATED_BY_ME | diff --git a/docs/models/listentitiesrequest.md b/docs/models/listentitiesrequest.md index 327a1f2f..c4ac2d31 100644 --- a/docs/models/listentitiesrequest.md +++ b/docs/models/listentitiesrequest.md @@ -13,4 +13,5 @@ | `include_fields` | List[[models.ListEntitiesRequestIncludeField](../models/listentitiesrequestincludefield.md)] | :heavy_minus_sign: | List of entity fields to return (that aren't returned by default) | | | `page_size` | *Optional[int]* | :heavy_minus_sign: | Hint to the server about how many results to send back. Server may return less. | 100 | | `cursor` | *Optional[str]* | :heavy_minus_sign: | Pagination cursor. A previously received opaque token representing the position in the overall results at which to start. | | -| `source` | *Optional[str]* | :heavy_minus_sign: | A string denoting the search surface from which the endpoint is called. | | \ No newline at end of file +| `source` | *Optional[str]* | :heavy_minus_sign: | A string denoting the search surface from which the endpoint is called. | | +| `request_type` | [Optional[models.RequestType]](../models/requesttype.md) | :heavy_minus_sign: | The type of request being made. | | \ No newline at end of file diff --git a/docs/models/message.md b/docs/models/message.md index 890662cd..2bc3e991 100644 --- a/docs/models/message.md +++ b/docs/models/message.md @@ -3,7 +3,7 @@ ## Fields -| Field | Type | Required | Description | -| -------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- | -| `role` | *Optional[str]* | :heavy_minus_sign: | The role of the message. | -| `content` | List[[models.MessageTextBlock](../models/messagetextblock.md)] | :heavy_minus_sign: | The content of the message. | \ No newline at end of file +| Field | Type | Required | Description | Example | +| -------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- | +| `role` | *Optional[str]* | :heavy_minus_sign: | The role of the message. | USER | +| `content` | List[[models.MessageTextBlock](../models/messagetextblock.md)] | :heavy_minus_sign: | The content of the message. | | \ No newline at end of file diff --git a/docs/models/relation.md b/docs/models/relation.md index 3e82b17b..1912e0f8 100644 --- a/docs/models/relation.md +++ b/docs/models/relation.md @@ -10,12 +10,14 @@ How this document relates to the including entity. | `ATTACHMENT` | ATTACHMENT | | `CANONICAL` | CANONICAL | | `CASE` | CASE | -| `CONTACT` | CONTACT | +| `CONTACT_LOWER` | contact | +| `CONTACT_UPPER` | CONTACT | | `CONVERSATION_MESSAGES` | CONVERSATION_MESSAGES | | `EXPERT` | EXPERT | | `FROM` | FROM | | `HIGHLIGHT` | HIGHLIGHT | -| `OPPORTUNITY` | OPPORTUNITY | +| `OPPORTUNITY_LOWER` | opportunity | +| `OPPORTUNITY_UPPER` | OPPORTUNITY | | `RECENT` | RECENT | | `SOURCE` | SOURCE | | `TICKET` | TICKET | diff --git a/docs/models/relationtype.md b/docs/models/relationtype.md index 7661e2ab..647876db 100644 --- a/docs/models/relationtype.md +++ b/docs/models/relationtype.md @@ -3,9 +3,10 @@ ## Values -| Name | Value | -| ----------- | ----------- | -| `EQUALS` | EQUALS | -| `ID_EQUALS` | ID_EQUALS | -| `LT` | LT | -| `GT` | GT | \ No newline at end of file +| Name | Value | +| ------------ | ------------ | +| `EQUALS` | EQUALS | +| `ID_EQUALS` | ID_EQUALS | +| `LT` | LT | +| `GT` | GT | +| `NOT_EQUALS` | NOT_EQUALS | \ No newline at end of file diff --git a/docs/models/requesttype.md b/docs/models/requesttype.md new file mode 100644 index 00000000..1859501a --- /dev/null +++ b/docs/models/requesttype.md @@ -0,0 +1,11 @@ +# RequestType + +The type of request being made. + + +## Values + +| Name | Value | +| ---------------- | ---------------- | +| `STANDARD` | STANDARD | +| `FULL_DIRECTORY` | FULL_DIRECTORY | \ No newline at end of file diff --git a/docs/models/timeperiodtype.md b/docs/models/timeperiodtype.md index 0078c02b..eb606293 100644 --- a/docs/models/timeperiodtype.md +++ b/docs/models/timeperiodtype.md @@ -5,9 +5,10 @@ Type of time period for which to run the report/policy. PAST_DAY is deprecated. ## Values -| Name | Value | -| ----------- | ----------- | -| `ALL_TIME` | ALL_TIME | -| `PAST_YEAR` | PAST_YEAR | -| `PAST_DAY` | PAST_DAY | -| `CUSTOM` | CUSTOM | \ No newline at end of file +| Name | Value | +| ------------- | ------------- | +| `ALL_TIME` | ALL_TIME | +| `PAST_YEAR` | PAST_YEAR | +| `PAST_DAY` | PAST_DAY | +| `CUSTOM` | CUSTOM | +| `LAST_N_DAYS` | LAST_N_DAYS | \ No newline at end of file diff --git a/docs/models/timerange.md b/docs/models/timerange.md index 074fcff6..56bde82f 100644 --- a/docs/models/timerange.md +++ b/docs/models/timerange.md @@ -3,7 +3,8 @@ ## Fields -| Field | Type | Required | Description | -| -------------------------------------------------------------------- | -------------------------------------------------------------------- | -------------------------------------------------------------------- | -------------------------------------------------------------------- | -| `start_time` | [date](https://docs.python.org/3/library/datetime.html#date-objects) | :heavy_minus_sign: | start time of the time range, applicable for the CUSTOM type. | -| `end_time` | [date](https://docs.python.org/3/library/datetime.html#date-objects) | :heavy_minus_sign: | end time of the time range, applicable for the CUSTOM type. | \ No newline at end of file +| Field | Type | Required | Description | +| ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | +| `start_time` | [date](https://docs.python.org/3/library/datetime.html#date-objects) | :heavy_minus_sign: | start time of the time range, applicable for the CUSTOM type. | +| `end_time` | [date](https://docs.python.org/3/library/datetime.html#date-objects) | :heavy_minus_sign: | end time of the time range, applicable for the CUSTOM type. | +| `last_n_days_value` | *Optional[int]* | :heavy_minus_sign: | The number of days to look back from the current time, applicable for the LAST_N_DAYS type. | \ No newline at end of file diff --git a/docs/models/warningtype.md b/docs/models/warningtype.md index bc7850ac..e40d81ce 100644 --- a/docs/models/warningtype.md +++ b/docs/models/warningtype.md @@ -5,11 +5,12 @@ The type of the warning. ## Values -| Name | Value | -| --------------------------- | --------------------------- | -| `LONG_QUERY` | LONG_QUERY | -| `QUOTED_PUNCTUATION` | QUOTED_PUNCTUATION | -| `PUNCTUATION_ONLY` | PUNCTUATION_ONLY | -| `COPYPASTED_QUOTES` | COPYPASTED_QUOTES | -| `INVALID_OPERATOR` | INVALID_OPERATOR | -| `MAYBE_INVALID_FACET_QUERY` | MAYBE_INVALID_FACET_QUERY | \ No newline at end of file +| Name | Value | +| ---------------------------- | ---------------------------- | +| `LONG_QUERY` | LONG_QUERY | +| `QUOTED_PUNCTUATION` | QUOTED_PUNCTUATION | +| `PUNCTUATION_ONLY` | PUNCTUATION_ONLY | +| `COPYPASTED_QUOTES` | COPYPASTED_QUOTES | +| `INVALID_OPERATOR` | INVALID_OPERATOR | +| `MAYBE_INVALID_FACET_QUERY` | MAYBE_INVALID_FACET_QUERY | +| `TOO_MANY_DATASOURCE_GROUPS` | TOO_MANY_DATASOURCE_GROUPS | \ No newline at end of file diff --git a/docs/sdks/agents/README.md b/docs/sdks/agents/README.md index 224945df..eea95d87 100644 --- a/docs/sdks/agents/README.md +++ b/docs/sdks/agents/README.md @@ -145,7 +145,11 @@ with Glean( api_token=os.getenv("GLEAN_API_TOKEN", ""), ) as glean: - res = glean.client.agents.run_stream(agent_id="") + res = glean.client.agents.run_stream(agent_id="", messages=[ + { + "role": "USER", + }, + ]) # Handle response print(res) @@ -187,7 +191,11 @@ with Glean( api_token=os.getenv("GLEAN_API_TOKEN", ""), ) as glean: - res = glean.client.agents.run(agent_id="") + res = glean.client.agents.run(agent_id="", messages=[ + { + "role": "USER", + }, + ]) # Handle response print(res) diff --git a/docs/sdks/answers/README.md b/docs/sdks/answers/README.md index d26a81e4..8c6be8a1 100644 --- a/docs/sdks/answers/README.md +++ b/docs/sdks/answers/README.md @@ -197,24 +197,24 @@ with Glean( ### Parameters -| Parameter | Type | Required | Description | Example | -| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `id` | *int* | :heavy_check_mark: | The opaque ID of the Answer. | 3 | -| `doc_id` | *Optional[str]* | :heavy_minus_sign: | Glean Document ID of the Answer. The Glean Document ID is supported for cases where the Answer ID isn't available. If both are available, using the Answer ID is preferred. | ANSWERS_answer_3 | -| `question` | *Optional[str]* | :heavy_minus_sign: | N/A | Why is the sky blue? | -| `question_variations` | List[*str*] | :heavy_minus_sign: | Additional ways of phrasing this question. | | -| `body_text` | *Optional[str]* | :heavy_minus_sign: | The plain text answer to the question. | From https://en.wikipedia.org/wiki/Diffuse_sky_radiation, the sky is blue because blue light is more strongly scattered than longer-wavelength light. | -| `board_id` | *Optional[int]* | :heavy_minus_sign: | The parent board ID of this Answer, or 0 if it's a floating Answer. | | -| `audience_filters` | List[[models.FacetFilter](../../models/facetfilter.md)] | :heavy_minus_sign: | Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search. | | -| `added_roles` | List[[models.UserRoleSpecification](../../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer added by the owner. | | -| `removed_roles` | List[[models.UserRoleSpecification](../../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer removed by the owner. | | -| `roles` | List[[models.UserRoleSpecification](../../models/userrolespecification.md)] | :heavy_minus_sign: | A list of roles for this answer explicitly granted by an owner, editor, or admin. | | -| `source_document_spec` | [Optional[models.DocumentSpecUnion]](../../models/documentspecunion.md) | :heavy_minus_sign: | N/A | | -| `source_type` | [Optional[models.EditAnswerRequestSourceType]](../../models/editanswerrequestsourcetype.md) | :heavy_minus_sign: | N/A | | -| `added_collections` | List[*int*] | :heavy_minus_sign: | IDs of Collections to which a document is added. | | -| `removed_collections` | List[*int*] | :heavy_minus_sign: | IDs of Collections from which a document is removed. | | -| `combined_answer_text` | [Optional[models.StructuredTextMutableProperties]](../../models/structuredtextmutableproperties.md) | :heavy_minus_sign: | N/A | | -| `retries` | [Optional[utils.RetryConfig]](../../models/utils/retryconfig.md) | :heavy_minus_sign: | Configuration to override the default retry behavior of the client. | | +| Parameter | Type | Required | Description | Example | +| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `id` | *int* | :heavy_check_mark: | The opaque ID of the Answer. | 3 | +| `doc_id` | *Optional[str]* | :heavy_minus_sign: | Glean Document ID of the Answer. The Glean Document ID is supported for cases where the Answer ID isn't available. If both are available, using the Answer ID is preferred. | ANSWERS_answer_3 | +| `question` | *Optional[str]* | :heavy_minus_sign: | N/A | Why is the sky blue? | +| `question_variations` | List[*str*] | :heavy_minus_sign: | Additional ways of phrasing this question. | | +| `body_text` | *Optional[str]* | :heavy_minus_sign: | The plain text answer to the question. | From https://en.wikipedia.org/wiki/Diffuse_sky_radiation, the sky is blue because blue light is more strongly scattered than longer-wavelength light. | +| `board_id` | *Optional[int]* | :heavy_minus_sign: | : warning: ** DEPRECATED **: This will be removed in a future release, please migrate away from it as soon as possible.

The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted. | | +| `audience_filters` | List[[models.FacetFilter](../../models/facetfilter.md)] | :heavy_minus_sign: | Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search. | | +| `added_roles` | List[[models.UserRoleSpecification](../../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer added by the owner. | | +| `removed_roles` | List[[models.UserRoleSpecification](../../models/userrolespecification.md)] | :heavy_minus_sign: | A list of user roles for the answer removed by the owner. | | +| `roles` | List[[models.UserRoleSpecification](../../models/userrolespecification.md)] | :heavy_minus_sign: | A list of roles for this answer explicitly granted by an owner, editor, or admin. | | +| `source_document_spec` | [Optional[models.DocumentSpecUnion]](../../models/documentspecunion.md) | :heavy_minus_sign: | N/A | | +| `source_type` | [Optional[models.EditAnswerRequestSourceType]](../../models/editanswerrequestsourcetype.md) | :heavy_minus_sign: | N/A | | +| `added_collections` | List[*int*] | :heavy_minus_sign: | IDs of Collections to which a document is added. | | +| `removed_collections` | List[*int*] | :heavy_minus_sign: | IDs of Collections from which a document is removed. | | +| `combined_answer_text` | [Optional[models.StructuredTextMutableProperties]](../../models/structuredtextmutableproperties.md) | :heavy_minus_sign: | N/A | | +| `retries` | [Optional[utils.RetryConfig]](../../models/utils/retryconfig.md) | :heavy_minus_sign: | Configuration to override the default retry behavior of the client. | | ### Response diff --git a/docs/sdks/entities/README.md b/docs/sdks/entities/README.md index 5792bcaf..70022991 100644 --- a/docs/sdks/entities/README.md +++ b/docs/sdks/entities/README.md @@ -10,7 +10,7 @@ ## list -List some set of details for all entities that fit the given criteria and return in the requested order. Does not support negation in filters, assumes relation type EQUALS. There is a limit of 10000 entities that can be retrieved via this endpoint. +List some set of details for all entities that fit the given criteria and return in the requested order. Does not support negation in filters, assumes relation type EQUALS. There is a limit of 10000 entities that can be retrieved via this endpoint, except when using FULL_DIRECTORY request type for people entities. ### Example Usage @@ -37,7 +37,7 @@ with Glean( }, ], }, - ], entity_type=models.ListEntitiesRequestEntityType.PEOPLE, page_size=100) + ], entity_type=models.ListEntitiesRequestEntityType.PEOPLE, page_size=100, request_type=models.RequestType.STANDARD) # Handle response print(res) @@ -57,6 +57,7 @@ with Glean( | `page_size` | *Optional[int]* | :heavy_minus_sign: | Hint to the server about how many results to send back. Server may return less. | 100 | | `cursor` | *Optional[str]* | :heavy_minus_sign: | Pagination cursor. A previously received opaque token representing the position in the overall results at which to start. | | | `source` | *Optional[str]* | :heavy_minus_sign: | A string denoting the search surface from which the endpoint is called. | | +| `request_type` | [Optional[models.RequestType]](../../models/requesttype.md) | :heavy_minus_sign: | The type of request being made. | | | `retries` | [Optional[utils.RetryConfig]](../../models/utils/retryconfig.md) | :heavy_minus_sign: | Configuration to override the default retry behavior of the client. | | ### Response diff --git a/pyproject.toml b/pyproject.toml index 9adb54e2..c906a50c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "glean-api-client" -version = "0.6.6" +version = "0.7.0" description = "Python Client SDK Generated by Speakeasy." authors = [{ name = "Glean Technologies, Inc." }] license = "MIT" diff --git a/speakeasyusagegen/.speakeasy/logs/naming.log b/speakeasyusagegen/.speakeasy/logs/naming.log index 48fef91d..327436a3 100644 --- a/speakeasyusagegen/.speakeasy/logs/naming.log +++ b/speakeasyusagegen/.speakeasy/logs/naming.log @@ -787,6 +787,7 @@ ListEntitiesRequest (filter: array, sort: array, entityType: enum ...) OrderBy (enum: ASC, DESC) ListEntitiesRequestEntityType (enum: PEOPLE, TEAMS, CUSTOM_ENTITIES) ListEntitiesRequestIncludeField (enum: PEOPLE, TEAMS, PEOPLE_DISTANCE ...) + RequestType (enum: STANDARD, FULL_DIRECTORY) ListentitiesResponse (HttpMeta: HTTPMetadata, ListEntitiesResponse: ListEntitiesResponse) ListEntitiesResponse (results: array, teamResults: array, customEntityResults: array ...) EntitiesSortOrder (enum: ENTITY_NAME, FIRST_NAME, LAST_NAME ...) @@ -851,7 +852,7 @@ GetpolicyResponse (HttpMeta: HTTPMetadata, GetDlpReportResponse: GetDlpReportRes InputOptions (urlGreenlist: array, datasourcesType: enum, datasources: array ...) DatasourcesType (enum: ALL, CUSTOM) TimePeriodType (enum: ALL_TIME, PAST_YEAR, PAST_DAY ...) - TimeRange (startTime: date-time, endTime: date-time) + TimeRange (startTime: date-time, endTime: date-time, lastNDaysValue: integer) ExternalSharingOptions (enabled: boolean, threshold: integer, thresholdEnabled: boolean ...) SharingOptions (enabled: boolean, threshold: integer, thresholdEnabled: boolean ...) SensitiveContentOptions (sensitiveInfoTypes: array, sensitiveTerms: array, sensitiveRegexes: array) diff --git a/src/glean/api_client/_version.py b/src/glean/api_client/_version.py index df7fe1fd..73611f72 100644 --- a/src/glean/api_client/_version.py +++ b/src/glean/api_client/_version.py @@ -3,10 +3,10 @@ import importlib.metadata __title__: str = "glean" -__version__: str = "0.6.6" +__version__: str = "0.7.0" __openapi_doc_version__: str = "0.9.0" -__gen_version__: str = "2.629.1" -__user_agent__: str = "speakeasy-sdk/python 0.6.6 2.629.1 0.9.0 glean" +__gen_version__: str = "2.651.2" +__user_agent__: str = "speakeasy-sdk/python 0.7.0 2.651.2 0.9.0 glean" try: if __package__ is not None: diff --git a/src/glean/api_client/agents.py b/src/glean/api_client/agents.py index 34387d76..c861e754 100644 --- a/src/glean/api_client/agents.py +++ b/src/glean/api_client/agents.py @@ -85,26 +85,15 @@ def retrieve( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.Agent) + return utils.unmarshal_json_response(models.Agent, http_res) if utils.match_response(http_res, ["400", "403", "404", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_async( self, @@ -182,26 +171,15 @@ async def retrieve_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.Agent) + return utils.unmarshal_json_response(models.Agent, http_res) if utils.match_response(http_res, ["400", "403", "404", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def retrieve_schemas( self, @@ -279,26 +257,15 @@ def retrieve_schemas( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.AgentSchemas) + return utils.unmarshal_json_response(models.AgentSchemas, http_res) if utils.match_response(http_res, ["400", "403", "404", "422", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_schemas_async( self, @@ -376,26 +343,15 @@ async def retrieve_schemas_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.AgentSchemas) + return utils.unmarshal_json_response(models.AgentSchemas, http_res) if utils.match_response(http_res, ["400", "403", "404", "422", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def list( self, @@ -473,26 +429,15 @@ def list( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.SearchAgentsResponse) + return utils.unmarshal_json_response(models.SearchAgentsResponse, http_res) if utils.match_response(http_res, ["400", "403", "404", "422", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def list_async( self, @@ -570,26 +515,15 @@ async def list_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.SearchAgentsResponse) + return utils.unmarshal_json_response(models.SearchAgentsResponse, http_res) if utils.match_response(http_res, ["400", "403", "404", "422", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def run_stream( self, @@ -683,23 +617,12 @@ def run_stream( http_res, ["400", "403", "404", "409", "422", "4XX"], "*" ): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def run_stream_async( self, @@ -793,23 +716,12 @@ async def run_stream_async( http_res, ["400", "403", "404", "409", "422", "4XX"], "*" ): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def run( self, @@ -898,28 +810,17 @@ def run( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.AgentRunWaitResponse) + return utils.unmarshal_json_response(models.AgentRunWaitResponse, http_res) if utils.match_response( http_res, ["400", "403", "404", "409", "422", "4XX"], "*" ): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def run_async( self, @@ -1008,25 +909,14 @@ async def run_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.AgentRunWaitResponse) + return utils.unmarshal_json_response(models.AgentRunWaitResponse, http_res) if utils.match_response( http_res, ["400", "403", "404", "409", "422", "4XX"], "*" ): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/announcements.py b/src/glean/api_client/announcements.py index 2b7b5bdc..6df6a779 100644 --- a/src/glean/api_client/announcements.py +++ b/src/glean/api_client/announcements.py @@ -131,26 +131,15 @@ def create( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.Announcement) + return utils.unmarshal_json_response(models.Announcement, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def create_async( self, @@ -273,26 +262,15 @@ async def create_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.Announcement) + return utils.unmarshal_json_response(models.Announcement, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def delete( self, @@ -373,23 +351,12 @@ def delete( return if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def delete_async( self, @@ -470,23 +437,12 @@ async def delete_async( return if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def update( self, @@ -612,26 +568,15 @@ def update( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.Announcement) + return utils.unmarshal_json_response(models.Announcement, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def update_async( self, @@ -757,23 +702,12 @@ async def update_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.Announcement) + return utils.unmarshal_json_response(models.Announcement, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/answers.py b/src/glean/api_client/answers.py index 1d62cf85..01377c69 100644 --- a/src/glean/api_client/answers.py +++ b/src/glean/api_client/answers.py @@ -85,26 +85,15 @@ def create( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.Answer) + return utils.unmarshal_json_response(models.Answer, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def create_async( self, @@ -182,26 +171,15 @@ async def create_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.Answer) + return utils.unmarshal_json_response(models.Answer, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def delete( self, @@ -285,23 +263,12 @@ def delete( return if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def delete_async( self, @@ -385,23 +352,12 @@ async def delete_async( return if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def update( self, @@ -459,7 +415,7 @@ def update( :param question: :param question_variations: Additional ways of phrasing this question. :param body_text: The plain text answer to the question. - :param board_id: The parent board ID of this Answer, or 0 if it's a floating Answer. + :param board_id: The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted. :param audience_filters: Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search. :param added_roles: A list of user roles for the answer added by the owner. :param removed_roles: A list of user roles for the answer removed by the owner. @@ -557,26 +513,15 @@ def update( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.Answer) + return utils.unmarshal_json_response(models.Answer, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def update_async( self, @@ -634,7 +579,7 @@ async def update_async( :param question: :param question_variations: Additional ways of phrasing this question. :param body_text: The plain text answer to the question. - :param board_id: The parent board ID of this Answer, or 0 if it's a floating Answer. + :param board_id: The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted. :param audience_filters: Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search. :param added_roles: A list of user roles for the answer added by the owner. :param removed_roles: A list of user roles for the answer removed by the owner. @@ -732,26 +677,15 @@ async def update_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.Answer) + return utils.unmarshal_json_response(models.Answer, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def retrieve( self, @@ -832,26 +766,15 @@ def retrieve( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetAnswerResponse) + return utils.unmarshal_json_response(models.GetAnswerResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_async( self, @@ -932,26 +855,15 @@ async def retrieve_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetAnswerResponse) + return utils.unmarshal_json_response(models.GetAnswerResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def list( self, @@ -1029,26 +941,15 @@ def list( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ListAnswersResponse) + return utils.unmarshal_json_response(models.ListAnswersResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def list_async( self, @@ -1126,23 +1027,12 @@ async def list_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ListAnswersResponse) + return utils.unmarshal_json_response(models.ListAnswersResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/basesdk.py b/src/glean/api_client/basesdk.py index 9f183967..d6cdc0da 100644 --- a/src/glean/api_client/basesdk.py +++ b/src/glean/api_client/basesdk.py @@ -244,7 +244,7 @@ def do(): if http_res is None: logger.debug("Raising no response SDK error") - raise errors.GleanError("No response received") + raise errors.NoResponseError("No response received") logger.debug( "Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s", @@ -265,7 +265,7 @@ def do(): http_res = result else: logger.debug("Raising unexpected SDK error") - raise errors.GleanError("Unexpected error occurred") + raise errors.GleanError("Unexpected error occurred", http_res) return http_res @@ -316,7 +316,7 @@ async def do(): if http_res is None: logger.debug("Raising no response SDK error") - raise errors.GleanError("No response received") + raise errors.NoResponseError("No response received") logger.debug( "Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s", @@ -337,7 +337,7 @@ async def do(): http_res = result else: logger.debug("Raising unexpected SDK error") - raise errors.GleanError("Unexpected error occurred") + raise errors.GleanError("Unexpected error occurred", http_res) return http_res diff --git a/src/glean/api_client/client_activity.py b/src/glean/api_client/client_activity.py index bff2a361..1ddd7f9a 100644 --- a/src/glean/api_client/client_activity.py +++ b/src/glean/api_client/client_activity.py @@ -88,23 +88,12 @@ def report( return if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def report_async( self, @@ -185,23 +174,12 @@ async def report_async( return if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def feedback( self, @@ -285,23 +263,12 @@ def feedback( return if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def feedback_async( self, @@ -385,20 +352,9 @@ async def feedback_async( return if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/client_authentication.py b/src/glean/api_client/client_authentication.py index 42fd7b0a..971e9237 100644 --- a/src/glean/api_client/client_authentication.py +++ b/src/glean/api_client/client_authentication.py @@ -80,26 +80,17 @@ def create_token( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.CreateAuthTokenResponse) + return utils.unmarshal_json_response( + models.CreateAuthTokenResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def create_token_async( self, @@ -172,23 +163,14 @@ async def create_token_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.CreateAuthTokenResponse) + return utils.unmarshal_json_response( + models.CreateAuthTokenResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/client_chat.py b/src/glean/api_client/client_chat.py index a8522b40..96ff6eee 100644 --- a/src/glean/api_client/client_chat.py +++ b/src/glean/api_client/client_chat.py @@ -136,26 +136,15 @@ def create( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ChatResponse) + return utils.unmarshal_json_response(models.ChatResponse, http_res) if utils.match_response(http_res, ["400", "401", "408", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def create_async( self, @@ -284,26 +273,15 @@ async def create_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ChatResponse) + return utils.unmarshal_json_response(models.ChatResponse, http_res) if utils.match_response(http_res, ["400", "401", "408", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def delete_all( self, @@ -381,23 +359,12 @@ def delete_all( return if utils.match_response(http_res, ["400", "401", "403", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def delete_all_async( self, @@ -475,23 +442,12 @@ async def delete_all_async( return if utils.match_response(http_res, ["400", "401", "403", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def delete( self, @@ -581,23 +537,12 @@ def delete( return if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def delete_async( self, @@ -687,23 +632,12 @@ async def delete_async( return if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def retrieve( self, @@ -786,26 +720,15 @@ def retrieve( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetChatResponse) + return utils.unmarshal_json_response(models.GetChatResponse, http_res) if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_async( self, @@ -888,26 +811,15 @@ async def retrieve_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetChatResponse) + return utils.unmarshal_json_response(models.GetChatResponse, http_res) if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def list( self, @@ -982,26 +894,15 @@ def list( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ListChatsResponse) + return utils.unmarshal_json_response(models.ListChatsResponse, http_res) if utils.match_response(http_res, ["401", "403", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def list_async( self, @@ -1076,26 +977,15 @@ async def list_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ListChatsResponse) + return utils.unmarshal_json_response(models.ListChatsResponse, http_res) if utils.match_response(http_res, ["401", "403", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def retrieve_application( self, @@ -1182,28 +1072,17 @@ def retrieve_application( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json( - http_res.text, models.GetChatApplicationResponse + return utils.unmarshal_json_response( + models.GetChatApplicationResponse, http_res ) if utils.match_response(http_res, ["400", "401", "403", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_application_async( self, @@ -1290,28 +1169,17 @@ async def retrieve_application_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json( - http_res.text, models.GetChatApplicationResponse + return utils.unmarshal_json_response( + models.GetChatApplicationResponse, http_res ) if utils.match_response(http_res, ["400", "401", "403", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def upload_files( self, @@ -1398,26 +1266,17 @@ def upload_files( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.UploadChatFilesResponse) + return utils.unmarshal_json_response( + models.UploadChatFilesResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def upload_files_async( self, @@ -1504,26 +1363,17 @@ async def upload_files_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.UploadChatFilesResponse) + return utils.unmarshal_json_response( + models.UploadChatFilesResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def retrieve_files( self, @@ -1610,26 +1460,15 @@ def retrieve_files( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetChatFilesResponse) + return utils.unmarshal_json_response(models.GetChatFilesResponse, http_res) if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_files_async( self, @@ -1716,26 +1555,15 @@ async def retrieve_files_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetChatFilesResponse) + return utils.unmarshal_json_response(models.GetChatFilesResponse, http_res) if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def delete_files( self, @@ -1825,23 +1653,12 @@ def delete_files( return if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def delete_files_async( self, @@ -1931,23 +1748,12 @@ async def delete_files_async( return if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def create_stream( self, @@ -2079,23 +1885,12 @@ def create_stream( return http_res.text if utils.match_response(http_res, ["400", "401", "408", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def create_stream_async( self, @@ -2227,20 +2022,9 @@ async def create_stream_async( return http_res.text if utils.match_response(http_res, ["400", "401", "408", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/client_documents.py b/src/glean/api_client/client_documents.py index 9981ff02..5fac224d 100644 --- a/src/glean/api_client/client_documents.py +++ b/src/glean/api_client/client_documents.py @@ -86,26 +86,17 @@ def retrieve_permissions( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetDocPermissionsResponse) + return utils.unmarshal_json_response( + models.GetDocPermissionsResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_permissions_async( self, @@ -183,26 +174,17 @@ async def retrieve_permissions_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetDocPermissionsResponse) + return utils.unmarshal_json_response( + models.GetDocPermissionsResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def retrieve( self, @@ -282,26 +264,15 @@ def retrieve( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetDocumentsResponse) + return utils.unmarshal_json_response(models.GetDocumentsResponse, http_res) if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_async( self, @@ -381,26 +352,15 @@ async def retrieve_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetDocumentsResponse) + return utils.unmarshal_json_response(models.GetDocumentsResponse, http_res) if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def retrieve_by_facets( self, @@ -489,28 +449,17 @@ def retrieve_by_facets( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json( - http_res.text, models.GetDocumentsByFacetsResponse + return utils.unmarshal_json_response( + models.GetDocumentsByFacetsResponse, http_res ) if utils.match_response(http_res, ["400", "401", "404", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_by_facets_async( self, @@ -599,28 +548,17 @@ async def retrieve_by_facets_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json( - http_res.text, models.GetDocumentsByFacetsResponse + return utils.unmarshal_json_response( + models.GetDocumentsByFacetsResponse, http_res ) if utils.match_response(http_res, ["400", "401", "404", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def summarize( self, @@ -714,26 +652,15 @@ def summarize( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.SummarizeResponse) + return utils.unmarshal_json_response(models.SummarizeResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def summarize_async( self, @@ -827,23 +754,12 @@ async def summarize_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.SummarizeResponse) + return utils.unmarshal_json_response(models.SummarizeResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/client_shortcuts.py b/src/glean/api_client/client_shortcuts.py index 900d1492..0fe8f0d1 100644 --- a/src/glean/api_client/client_shortcuts.py +++ b/src/glean/api_client/client_shortcuts.py @@ -87,26 +87,17 @@ def create( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.CreateShortcutResponse) + return utils.unmarshal_json_response( + models.CreateShortcutResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def create_async( self, @@ -186,26 +177,17 @@ async def create_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.CreateShortcutResponse) + return utils.unmarshal_json_response( + models.CreateShortcutResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def delete( self, @@ -286,23 +268,12 @@ def delete( return if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def delete_async( self, @@ -383,23 +354,12 @@ async def delete_async( return if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def retrieve( self, @@ -479,26 +439,15 @@ def retrieve( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetShortcutResponse) + return utils.unmarshal_json_response(models.GetShortcutResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_async( self, @@ -578,26 +527,15 @@ async def retrieve_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetShortcutResponse) + return utils.unmarshal_json_response(models.GetShortcutResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def list( self, @@ -696,28 +634,17 @@ def list( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json( - http_res.text, models.ListShortcutsPaginatedResponse + return utils.unmarshal_json_response( + models.ListShortcutsPaginatedResponse, http_res ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def list_async( self, @@ -816,28 +743,17 @@ async def list_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json( - http_res.text, models.ListShortcutsPaginatedResponse + return utils.unmarshal_json_response( + models.ListShortcutsPaginatedResponse, http_res ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def update( self, @@ -953,26 +869,17 @@ def update( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.UpdateShortcutResponse) + return utils.unmarshal_json_response( + models.UpdateShortcutResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def update_async( self, @@ -1088,23 +995,14 @@ async def update_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.UpdateShortcutResponse) + return utils.unmarshal_json_response( + models.UpdateShortcutResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/client_verification.py b/src/glean/api_client/client_verification.py index 2cc2a343..2fe108d5 100644 --- a/src/glean/api_client/client_verification.py +++ b/src/glean/api_client/client_verification.py @@ -94,26 +94,15 @@ def add_reminder( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.Verification) + return utils.unmarshal_json_response(models.Verification, http_res) if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def add_reminder_async( self, @@ -200,26 +189,15 @@ async def add_reminder_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.Verification) + return utils.unmarshal_json_response(models.Verification, http_res) if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def list( self, @@ -294,26 +272,15 @@ def list( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.VerificationFeed) + return utils.unmarshal_json_response(models.VerificationFeed, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def list_async( self, @@ -388,26 +355,15 @@ async def list_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.VerificationFeed) + return utils.unmarshal_json_response(models.VerificationFeed, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def verify( self, @@ -488,26 +444,15 @@ def verify( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.Verification) + return utils.unmarshal_json_response(models.Verification, http_res) if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def verify_async( self, @@ -588,23 +533,12 @@ async def verify_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.Verification) + return utils.unmarshal_json_response(models.Verification, http_res) if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/collections.py b/src/glean/api_client/collections.py index 351fdb74..d57ed50b 100644 --- a/src/glean/api_client/collections.py +++ b/src/glean/api_client/collections.py @@ -96,28 +96,17 @@ def add_items( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json( - http_res.text, models.AddCollectionItemsResponse + return utils.unmarshal_json_response( + models.AddCollectionItemsResponse, http_res ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def add_items_async( self, @@ -206,28 +195,17 @@ async def add_items_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json( - http_res.text, models.AddCollectionItemsResponse + return utils.unmarshal_json_response( + models.AddCollectionItemsResponse, http_res ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def create( self, @@ -354,31 +332,22 @@ def create( response_data: Any = None if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.CreateCollectionResponse) + return utils.unmarshal_json_response( + models.CreateCollectionResponse, http_res + ) if utils.match_response(http_res, "422", "application/json"): - response_data = utils.unmarshal_json( - http_res.text, errors.CollectionErrorData + response_data = utils.unmarshal_json_response( + errors.CollectionErrorData, http_res ) - raise errors.CollectionError(data=response_data) + raise errors.CollectionError(response_data, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def create_async( self, @@ -505,31 +474,22 @@ async def create_async( response_data: Any = None if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.CreateCollectionResponse) + return utils.unmarshal_json_response( + models.CreateCollectionResponse, http_res + ) if utils.match_response(http_res, "422", "application/json"): - response_data = utils.unmarshal_json( - http_res.text, errors.CollectionErrorData + response_data = utils.unmarshal_json_response( + errors.CollectionErrorData, http_res ) - raise errors.CollectionError(data=response_data) + raise errors.CollectionError(response_data, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def delete( self, @@ -613,29 +573,18 @@ def delete( if utils.match_response(http_res, "200", "*"): return if utils.match_response(http_res, "422", "application/json"): - response_data = utils.unmarshal_json( - http_res.text, errors.CollectionErrorData + response_data = utils.unmarshal_json_response( + errors.CollectionErrorData, http_res ) - raise errors.CollectionError(data=response_data) + raise errors.CollectionError(response_data, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def delete_async( self, @@ -719,29 +668,18 @@ async def delete_async( if utils.match_response(http_res, "200", "*"): return if utils.match_response(http_res, "422", "application/json"): - response_data = utils.unmarshal_json( - http_res.text, errors.CollectionErrorData + response_data = utils.unmarshal_json_response( + errors.CollectionErrorData, http_res ) - raise errors.CollectionError(data=response_data) + raise errors.CollectionError(response_data, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def delete_item( self, @@ -825,28 +763,17 @@ def delete_item( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json( - http_res.text, models.DeleteCollectionItemResponse + return utils.unmarshal_json_response( + models.DeleteCollectionItemResponse, http_res ) if utils.match_response(http_res, ["400", "401", "422", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def delete_item_async( self, @@ -930,28 +857,17 @@ async def delete_item_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json( - http_res.text, models.DeleteCollectionItemResponse + return utils.unmarshal_json_response( + models.DeleteCollectionItemResponse, http_res ) if utils.match_response(http_res, ["400", "401", "422", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def update( self, @@ -1078,31 +994,22 @@ def update( response_data: Any = None if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.EditCollectionResponse) + return utils.unmarshal_json_response( + models.EditCollectionResponse, http_res + ) if utils.match_response(http_res, "422", "application/json"): - response_data = utils.unmarshal_json( - http_res.text, errors.CollectionErrorData + response_data = utils.unmarshal_json_response( + errors.CollectionErrorData, http_res ) - raise errors.CollectionError(data=response_data) + raise errors.CollectionError(response_data, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def update_async( self, @@ -1229,31 +1136,22 @@ async def update_async( response_data: Any = None if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.EditCollectionResponse) + return utils.unmarshal_json_response( + models.EditCollectionResponse, http_res + ) if utils.match_response(http_res, "422", "application/json"): - response_data = utils.unmarshal_json( - http_res.text, errors.CollectionErrorData + response_data = utils.unmarshal_json_response( + errors.CollectionErrorData, http_res ) - raise errors.CollectionError(data=response_data) + raise errors.CollectionError(response_data, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def update_item( self, @@ -1343,28 +1241,17 @@ def update_item( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json( - http_res.text, models.EditCollectionItemResponse + return utils.unmarshal_json_response( + models.EditCollectionItemResponse, http_res ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def update_item_async( self, @@ -1454,28 +1341,17 @@ async def update_item_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json( - http_res.text, models.EditCollectionItemResponse + return utils.unmarshal_json_response( + models.EditCollectionItemResponse, http_res ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def retrieve( self, @@ -1562,26 +1438,15 @@ def retrieve( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetCollectionResponse) + return utils.unmarshal_json_response(models.GetCollectionResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_async( self, @@ -1668,26 +1533,15 @@ async def retrieve_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetCollectionResponse) + return utils.unmarshal_json_response(models.GetCollectionResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def list( self, @@ -1771,26 +1625,17 @@ def list( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ListCollectionsResponse) + return utils.unmarshal_json_response( + models.ListCollectionsResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def list_async( self, @@ -1874,23 +1719,14 @@ async def list_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ListCollectionsResponse) + return utils.unmarshal_json_response( + models.ListCollectionsResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/datasources.py b/src/glean/api_client/datasources.py index e8b57579..af982973 100644 --- a/src/glean/api_client/datasources.py +++ b/src/glean/api_client/datasources.py @@ -191,23 +191,12 @@ def add( return if utils.match_response(http_res, ["400", "401", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def add_async( self, @@ -391,23 +380,12 @@ async def add_async( return if utils.match_response(http_res, ["400", "401", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def retrieve_config( self, @@ -485,26 +463,17 @@ def retrieve_config( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.CustomDatasourceConfig) + return utils.unmarshal_json_response( + models.CustomDatasourceConfig, http_res + ) if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_config_async( self, @@ -582,23 +551,14 @@ async def retrieve_config_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.CustomDatasourceConfig) + return utils.unmarshal_json_response( + models.CustomDatasourceConfig, http_res + ) if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/entities.py b/src/glean/api_client/entities.py index 1b88e1c2..0097ec2f 100644 --- a/src/glean/api_client/entities.py +++ b/src/glean/api_client/entities.py @@ -27,6 +27,7 @@ def list( page_size: Optional[int] = None, cursor: Optional[str] = None, source: Optional[str] = None, + request_type: Optional[models.RequestType] = models.RequestType.STANDARD, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, @@ -34,7 +35,7 @@ def list( ) -> models.ListEntitiesResponse: r"""List entities - List some set of details for all entities that fit the given criteria and return in the requested order. Does not support negation in filters, assumes relation type EQUALS. There is a limit of 10000 entities that can be retrieved via this endpoint. + List some set of details for all entities that fit the given criteria and return in the requested order. Does not support negation in filters, assumes relation type EQUALS. There is a limit of 10000 entities that can be retrieved via this endpoint, except when using FULL_DIRECTORY request type for people entities. :param filter_: :param sort: Use EntitiesSortOrder enum for SortOptions.sortBy @@ -45,6 +46,7 @@ def list( :param page_size: Hint to the server about how many results to send back. Server may return less. :param cursor: Pagination cursor. A previously received opaque token representing the position in the overall results at which to start. :param source: A string denoting the search surface from which the endpoint is called. + :param request_type: The type of request being made. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds @@ -72,6 +74,7 @@ def list( page_size=page_size, cursor=cursor, source=source, + request_type=request_type, ) req = self._build_request( @@ -117,26 +120,15 @@ def list( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ListEntitiesResponse) + return utils.unmarshal_json_response(models.ListEntitiesResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def list_async( self, @@ -156,6 +148,7 @@ async def list_async( page_size: Optional[int] = None, cursor: Optional[str] = None, source: Optional[str] = None, + request_type: Optional[models.RequestType] = models.RequestType.STANDARD, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, @@ -163,7 +156,7 @@ async def list_async( ) -> models.ListEntitiesResponse: r"""List entities - List some set of details for all entities that fit the given criteria and return in the requested order. Does not support negation in filters, assumes relation type EQUALS. There is a limit of 10000 entities that can be retrieved via this endpoint. + List some set of details for all entities that fit the given criteria and return in the requested order. Does not support negation in filters, assumes relation type EQUALS. There is a limit of 10000 entities that can be retrieved via this endpoint, except when using FULL_DIRECTORY request type for people entities. :param filter_: :param sort: Use EntitiesSortOrder enum for SortOptions.sortBy @@ -174,6 +167,7 @@ async def list_async( :param page_size: Hint to the server about how many results to send back. Server may return less. :param cursor: Pagination cursor. A previously received opaque token representing the position in the overall results at which to start. :param source: A string denoting the search surface from which the endpoint is called. + :param request_type: The type of request being made. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds @@ -201,6 +195,7 @@ async def list_async( page_size=page_size, cursor=cursor, source=source, + request_type=request_type, ) req = self._build_request_async( @@ -246,26 +241,15 @@ async def list_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ListEntitiesResponse) + return utils.unmarshal_json_response(models.ListEntitiesResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def read_people( self, @@ -358,26 +342,15 @@ def read_people( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.PeopleResponse) + return utils.unmarshal_json_response(models.PeopleResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def read_people_async( self, @@ -470,23 +443,12 @@ async def read_people_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.PeopleResponse) + return utils.unmarshal_json_response(models.PeopleResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/errors/__init__.py b/src/glean/api_client/errors/__init__.py index dda3805d..6d6b0896 100644 --- a/src/glean/api_client/errors/__init__.py +++ b/src/glean/api_client/errors/__init__.py @@ -5,23 +5,32 @@ if TYPE_CHECKING: from .collectionerror import CollectionError, CollectionErrorData + from .gleanbaseerror import GleanBaseError from .gleandataerror import GleanDataError, GleanDataErrorData from .gleanerror import GleanError + from .no_response_error import NoResponseError + from .responsevalidationerror import ResponseValidationError __all__ = [ "CollectionError", "CollectionErrorData", + "GleanBaseError", "GleanDataError", "GleanDataErrorData", "GleanError", + "NoResponseError", + "ResponseValidationError", ] _dynamic_imports: dict[str, str] = { "CollectionError": ".collectionerror", "CollectionErrorData": ".collectionerror", + "GleanBaseError": ".gleanbaseerror", "GleanDataError": ".gleandataerror", "GleanDataErrorData": ".gleandataerror", "GleanError": ".gleanerror", + "NoResponseError": ".no_response_error", + "ResponseValidationError": ".responsevalidationerror", } diff --git a/src/glean/api_client/errors/collectionerror.py b/src/glean/api_client/errors/collectionerror.py index 49cc9653..686fff1a 100644 --- a/src/glean/api_client/errors/collectionerror.py +++ b/src/glean/api_client/errors/collectionerror.py @@ -1,10 +1,12 @@ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from __future__ import annotations -from glean.api_client import utils +from glean.api_client.errors import GleanBaseError from glean.api_client.models import collectionerror as models_collectionerror from glean.api_client.types import BaseModel +import httpx import pydantic +from typing import Optional from typing_extensions import Annotated @@ -15,11 +17,15 @@ class CollectionErrorData(BaseModel): ] -class CollectionError(Exception): +class CollectionError(GleanBaseError): data: CollectionErrorData - def __init__(self, data: CollectionErrorData): + def __init__( + self, + data: CollectionErrorData, + raw_response: httpx.Response, + body: Optional[str] = None, + ): + message = body or raw_response.text + super().__init__(message, raw_response, body) self.data = data - - def __str__(self) -> str: - return utils.marshal_json(self.data, CollectionErrorData) diff --git a/src/glean/api_client/errors/gleanbaseerror.py b/src/glean/api_client/errors/gleanbaseerror.py new file mode 100644 index 00000000..b3ca1543 --- /dev/null +++ b/src/glean/api_client/errors/gleanbaseerror.py @@ -0,0 +1,26 @@ +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" + +import httpx +from typing import Optional + + +class GleanBaseError(Exception): + """The base class for all HTTP error responses.""" + + message: str + status_code: int + body: str + headers: httpx.Headers + raw_response: httpx.Response + + def __init__( + self, message: str, raw_response: httpx.Response, body: Optional[str] = None + ): + self.message = message + self.status_code = raw_response.status_code + self.body = body if body is not None else raw_response.text + self.headers = raw_response.headers + self.raw_response = raw_response + + def __str__(self): + return self.message diff --git a/src/glean/api_client/errors/gleandataerror.py b/src/glean/api_client/errors/gleandataerror.py index cce205b6..f2ac2305 100644 --- a/src/glean/api_client/errors/gleandataerror.py +++ b/src/glean/api_client/errors/gleandataerror.py @@ -1,12 +1,13 @@ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from __future__ import annotations -from glean.api_client import utils +from glean.api_client.errors import GleanBaseError from glean.api_client.models import ( errormessage as models_errormessage, invalidoperatorvalueerror as models_invalidoperatorvalueerror, ) from glean.api_client.types import BaseModel +import httpx import pydantic from typing import List, Optional from typing_extensions import Annotated @@ -35,11 +36,15 @@ class GleanDataErrorData(BaseModel): ] = None -class GleanDataError(Exception): +class GleanDataError(GleanBaseError): data: GleanDataErrorData - def __init__(self, data: GleanDataErrorData): + def __init__( + self, + data: GleanDataErrorData, + raw_response: httpx.Response, + body: Optional[str] = None, + ): + message = body or raw_response.text + super().__init__(message, raw_response, body) self.data = data - - def __str__(self) -> str: - return utils.marshal_json(self.data, GleanDataErrorData) diff --git a/src/glean/api_client/errors/gleanerror.py b/src/glean/api_client/errors/gleanerror.py index c40871ca..272b00ca 100644 --- a/src/glean/api_client/errors/gleanerror.py +++ b/src/glean/api_client/errors/gleanerror.py @@ -1,22 +1,38 @@ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" -from dataclasses import dataclass -from typing import Optional import httpx +from typing import Optional + +from glean.api_client.errors import GleanBaseError + +MAX_MESSAGE_LEN = 10_000 + + +class GleanError(GleanBaseError): + """The fallback error class if no more specific error class is matched.""" + + def __init__( + self, message: str, raw_response: httpx.Response, body: Optional[str] = None + ): + body_display = body or raw_response.text or '""' + if message: + message += ": " + message += f"Status {raw_response.status_code}" -@dataclass -class GleanError(Exception): - """Represents an error returned by the API.""" + headers = raw_response.headers + content_type = headers.get("content-type", '""') + if content_type != "application/json": + if " " in content_type: + content_type = f'"{content_type}"' + message += f" Content-Type {content_type}" - message: str - status_code: int = -1 - body: str = "" - raw_response: Optional[httpx.Response] = None + if len(body_display) > MAX_MESSAGE_LEN: + truncated = body_display[:MAX_MESSAGE_LEN] + remaining = len(body_display) - MAX_MESSAGE_LEN + body_display = f"{truncated}...and {remaining} more chars" - def __str__(self): - body = "" - if len(self.body) > 0: - body = f"\n{self.body}" + message += f". Body: {body_display}" + message = message.strip() - return f"{self.message}: Status {self.status_code}{body}" + super().__init__(message, raw_response, body) diff --git a/src/glean/api_client/errors/no_response_error.py b/src/glean/api_client/errors/no_response_error.py new file mode 100644 index 00000000..f98beea2 --- /dev/null +++ b/src/glean/api_client/errors/no_response_error.py @@ -0,0 +1,13 @@ +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" + +class NoResponseError(Exception): + """Error raised when no HTTP response is received from the server.""" + + message: str + + def __init__(self, message: str = "No response received"): + self.message = message + super().__init__(message) + + def __str__(self): + return self.message diff --git a/src/glean/api_client/errors/responsevalidationerror.py b/src/glean/api_client/errors/responsevalidationerror.py new file mode 100644 index 00000000..0c279c12 --- /dev/null +++ b/src/glean/api_client/errors/responsevalidationerror.py @@ -0,0 +1,25 @@ +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" + +import httpx +from typing import Optional + +from glean.api_client.errors import GleanBaseError + + +class ResponseValidationError(GleanBaseError): + """Error raised when there is a type mismatch between the response data and the expected Pydantic model.""" + + def __init__( + self, + message: str, + raw_response: httpx.Response, + cause: Exception, + body: Optional[str] = None, + ): + message = f"{message}: {cause}" + super().__init__(message, raw_response, body) + + @property + def cause(self): + """Normally the Pydantic ValidationError""" + return self.__cause__ diff --git a/src/glean/api_client/indexing_authentication.py b/src/glean/api_client/indexing_authentication.py index f45bc56f..cfa3b750 100644 --- a/src/glean/api_client/indexing_authentication.py +++ b/src/glean/api_client/indexing_authentication.py @@ -75,26 +75,15 @@ def rotate_token( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.RotateTokenResponse) + return utils.unmarshal_json_response(models.RotateTokenResponse, http_res) if utils.match_response(http_res, ["400", "401", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def rotate_token_async( self, @@ -162,23 +151,12 @@ async def rotate_token_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.RotateTokenResponse) + return utils.unmarshal_json_response(models.RotateTokenResponse, http_res) if utils.match_response(http_res, ["400", "401", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/indexing_datasource.py b/src/glean/api_client/indexing_datasource.py index 159c9772..f246a049 100644 --- a/src/glean/api_client/indexing_datasource.py +++ b/src/glean/api_client/indexing_datasource.py @@ -85,28 +85,17 @@ def status( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json( - http_res.text, models.DebugDatasourceStatusResponse + return utils.unmarshal_json_response( + models.DebugDatasourceStatusResponse, http_res ) if utils.match_response(http_res, ["400", "401", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def status_async( self, @@ -184,25 +173,14 @@ async def status_async( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json( - http_res.text, models.DebugDatasourceStatusResponse + return utils.unmarshal_json_response( + models.DebugDatasourceStatusResponse, http_res ) if utils.match_response(http_res, ["400", "401", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/indexing_documents.py b/src/glean/api_client/indexing_documents.py index fb5c49c9..b08b42f7 100644 --- a/src/glean/api_client/indexing_documents.py +++ b/src/glean/api_client/indexing_documents.py @@ -92,23 +92,12 @@ def add_or_update( return if utils.match_response(http_res, ["400", "401", "409", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def add_or_update_async( self, @@ -192,23 +181,12 @@ async def add_or_update_async( return if utils.match_response(http_res, ["400", "401", "409", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def index( self, @@ -299,23 +277,12 @@ def index( return if utils.match_response(http_res, ["400", "401", "409", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def index_async( self, @@ -406,23 +373,12 @@ async def index_async( return if utils.match_response(http_res, ["400", "401", "409", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def bulk_index( self, @@ -525,23 +481,12 @@ def bulk_index( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def bulk_index_async( self, @@ -644,23 +589,12 @@ async def bulk_index_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def process_all( self, @@ -763,23 +697,12 @@ def process_all( return if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def process_all_async( self, @@ -882,23 +805,12 @@ async def process_all_async( return if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def delete( self, @@ -988,23 +900,12 @@ def delete( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def delete_async( self, @@ -1094,23 +995,12 @@ async def delete_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def debug( self, @@ -1203,26 +1093,15 @@ def debug( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json(http_res.text, models.DebugDocumentResponse) + return utils.unmarshal_json_response(models.DebugDocumentResponse, http_res) if utils.match_response(http_res, ["400", "401", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def debug_async( self, @@ -1315,26 +1194,15 @@ async def debug_async( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json(http_res.text, models.DebugDocumentResponse) + return utils.unmarshal_json_response(models.DebugDocumentResponse, http_res) if utils.match_response(http_res, ["400", "401", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def debug_many( self, @@ -1429,26 +1297,17 @@ def debug_many( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json(http_res.text, models.DebugDocumentsResponse) + return utils.unmarshal_json_response( + models.DebugDocumentsResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def debug_many_async( self, @@ -1543,26 +1402,17 @@ async def debug_many_async( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json(http_res.text, models.DebugDocumentsResponse) + return utils.unmarshal_json_response( + models.DebugDocumentsResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def check_access( self, @@ -1652,28 +1502,17 @@ def check_access( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json( - http_res.text, models.CheckDocumentAccessResponse + return utils.unmarshal_json_response( + models.CheckDocumentAccessResponse, http_res ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def check_access_async( self, @@ -1763,28 +1602,17 @@ async def check_access_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json( - http_res.text, models.CheckDocumentAccessResponse + return utils.unmarshal_json_response( + models.CheckDocumentAccessResponse, http_res ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) @deprecated( "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible." @@ -1874,26 +1702,17 @@ def status( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetDocumentStatusResponse) + return utils.unmarshal_json_response( + models.GetDocumentStatusResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) @deprecated( "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible." @@ -1983,26 +1802,17 @@ async def status_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetDocumentStatusResponse) + return utils.unmarshal_json_response( + models.GetDocumentStatusResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) @deprecated( "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible." @@ -2086,26 +1896,17 @@ def count( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetDocumentCountResponse) + return utils.unmarshal_json_response( + models.GetDocumentCountResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) @deprecated( "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible." @@ -2189,23 +1990,14 @@ async def count_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetDocumentCountResponse) + return utils.unmarshal_json_response( + models.GetDocumentCountResponse, http_res + ) if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/indexing_permissions.py b/src/glean/api_client/indexing_permissions.py index 963deccc..822eef5a 100644 --- a/src/glean/api_client/indexing_permissions.py +++ b/src/glean/api_client/indexing_permissions.py @@ -105,23 +105,12 @@ def update_permissions( return if utils.match_response(http_res, ["400", "401", "409", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def update_permissions_async( self, @@ -219,23 +208,12 @@ async def update_permissions_async( return if utils.match_response(http_res, ["400", "401", "409", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def index_user( self, @@ -324,23 +302,12 @@ def index_user( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def index_user_async( self, @@ -429,23 +396,12 @@ async def index_user_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def bulk_index_users( self, @@ -549,23 +505,12 @@ def bulk_index_users( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def bulk_index_users_async( self, @@ -669,23 +614,12 @@ async def bulk_index_users_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def index_group( self, @@ -774,23 +708,12 @@ def index_group( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def index_group_async( self, @@ -879,23 +802,12 @@ async def index_group_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def bulk_index_groups( self, @@ -999,23 +911,12 @@ def bulk_index_groups( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def bulk_index_groups_async( self, @@ -1119,23 +1020,12 @@ async def bulk_index_groups_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def index_membership( self, @@ -1227,23 +1117,12 @@ def index_membership( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def index_membership_async( self, @@ -1335,23 +1214,12 @@ async def index_membership_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def bulk_index_memberships( self, @@ -1455,23 +1323,12 @@ def bulk_index_memberships( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def bulk_index_memberships_async( self, @@ -1575,23 +1432,12 @@ async def bulk_index_memberships_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def process_memberships( self, @@ -1684,23 +1530,12 @@ def process_memberships( return if utils.match_response(http_res, ["400", "401", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def process_memberships_async( self, @@ -1793,23 +1628,12 @@ async def process_memberships_async( return if utils.match_response(http_res, ["400", "401", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def delete_user( self, @@ -1896,23 +1720,12 @@ def delete_user( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def delete_user_async( self, @@ -1999,23 +1812,12 @@ async def delete_user_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def delete_group( self, @@ -2102,23 +1904,12 @@ def delete_group( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def delete_group_async( self, @@ -2205,23 +1996,12 @@ async def delete_group_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def delete_membership( self, @@ -2313,23 +2093,12 @@ def delete_membership( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def delete_membership_async( self, @@ -2421,23 +2190,12 @@ async def delete_membership_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def authorize_beta_users( self, @@ -2521,23 +2279,12 @@ def authorize_beta_users( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def authorize_beta_users_async( self, @@ -2621,20 +2368,9 @@ async def authorize_beta_users_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/indexing_shortcuts.py b/src/glean/api_client/indexing_shortcuts.py index e97ee2fb..03905e31 100644 --- a/src/glean/api_client/indexing_shortcuts.py +++ b/src/glean/api_client/indexing_shortcuts.py @@ -104,23 +104,12 @@ def bulk_index( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def bulk_index_async( self, @@ -217,23 +206,12 @@ async def bulk_index_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def upload( self, @@ -330,23 +308,12 @@ def upload( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def upload_async( self, @@ -443,20 +410,9 @@ async def upload_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/insights.py b/src/glean/api_client/insights.py index aac70ccf..5ade3df6 100644 --- a/src/glean/api_client/insights.py +++ b/src/glean/api_client/insights.py @@ -117,26 +117,15 @@ def retrieve( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.InsightsResponse) + return utils.unmarshal_json_response(models.InsightsResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_async( self, @@ -246,23 +235,12 @@ async def retrieve_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.InsightsResponse) + return utils.unmarshal_json_response(models.InsightsResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/messages.py b/src/glean/api_client/messages.py index 8bab29c5..c21250c2 100644 --- a/src/glean/api_client/messages.py +++ b/src/glean/api_client/messages.py @@ -106,26 +106,15 @@ def retrieve( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.MessagesResponse) + return utils.unmarshal_json_response(models.MessagesResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_async( self, @@ -224,23 +213,12 @@ async def retrieve_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.MessagesResponse) + return utils.unmarshal_json_response(models.MessagesResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/models/__init__.py b/src/glean/api_client/models/__init__.py index 5dd91165..62d25912 100644 --- a/src/glean/api_client/models/__init__.py +++ b/src/glean/api_client/models/__init__.py @@ -812,6 +812,7 @@ ListEntitiesRequestEntityType, ListEntitiesRequestIncludeField, ListEntitiesRequestTypedDict, + RequestType, ) from .listentitiesresponse import ( ListEntitiesResponse, @@ -1980,6 +1981,7 @@ "ReportStatusResponse", "ReportStatusResponseStatus", "ReportStatusResponseTypedDict", + "RequestType", "ResponseHint", "ResponseStatus", "RestrictionFilters", @@ -2788,6 +2790,7 @@ "ListEntitiesRequestEntityType": ".listentitiesrequest", "ListEntitiesRequestIncludeField": ".listentitiesrequest", "ListEntitiesRequestTypedDict": ".listentitiesrequest", + "RequestType": ".listentitiesrequest", "ListEntitiesResponse": ".listentitiesresponse", "ListEntitiesResponseTypedDict": ".listentitiesresponse", "ListpinsRequest": ".listpinsop", diff --git a/src/glean/api_client/models/answer.py b/src/glean/api_client/models/answer.py index 000e5893..5f3f9b1c 100644 --- a/src/glean/api_client/models/answer.py +++ b/src/glean/api_client/models/answer.py @@ -41,7 +41,7 @@ class AnswerTypedDict(TypedDict): body_text: NotRequired[str] r"""The plain text answer to the question.""" board_id: NotRequired[int] - r"""The parent board ID of this Answer, or 0 if it's a floating Answer.""" + r"""The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted.""" audience_filters: NotRequired[List[FacetFilterTypedDict]] r"""Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search.""" added_roles: NotRequired[List["UserRoleSpecificationTypedDict"]] @@ -87,8 +87,14 @@ class Answer(BaseModel): body_text: Annotated[Optional[str], pydantic.Field(alias="bodyText")] = None r"""The plain text answer to the question.""" - board_id: Annotated[Optional[int], pydantic.Field(alias="boardId")] = None - r"""The parent board ID of this Answer, or 0 if it's a floating Answer.""" + board_id: Annotated[ + Optional[int], + pydantic.Field( + deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible.", + alias="boardId", + ), + ] = None + r"""The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted.""" audience_filters: Annotated[ Optional[List[FacetFilter]], pydantic.Field(alias="audienceFilters") diff --git a/src/glean/api_client/models/answercreationdata.py b/src/glean/api_client/models/answercreationdata.py index b3c6f130..a640029f 100644 --- a/src/glean/api_client/models/answercreationdata.py +++ b/src/glean/api_client/models/answercreationdata.py @@ -27,7 +27,7 @@ class AnswerCreationDataTypedDict(TypedDict): body_text: NotRequired[str] r"""The plain text answer to the question.""" board_id: NotRequired[int] - r"""The parent board ID of this Answer, or 0 if it's a floating Answer.""" + r"""The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted.""" audience_filters: NotRequired[List[FacetFilterTypedDict]] r"""Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search.""" added_roles: NotRequired[List[UserRoleSpecificationTypedDict]] @@ -54,8 +54,14 @@ class AnswerCreationData(BaseModel): body_text: Annotated[Optional[str], pydantic.Field(alias="bodyText")] = None r"""The plain text answer to the question.""" - board_id: Annotated[Optional[int], pydantic.Field(alias="boardId")] = None - r"""The parent board ID of this Answer, or 0 if it's a floating Answer.""" + board_id: Annotated[ + Optional[int], + pydantic.Field( + deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible.", + alias="boardId", + ), + ] = None + r"""The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted.""" audience_filters: Annotated[ Optional[List[FacetFilter]], pydantic.Field(alias="audienceFilters") diff --git a/src/glean/api_client/models/editanswerrequest.py b/src/glean/api_client/models/editanswerrequest.py index b2df1749..e190bebc 100644 --- a/src/glean/api_client/models/editanswerrequest.py +++ b/src/glean/api_client/models/editanswerrequest.py @@ -31,7 +31,7 @@ class EditAnswerRequestTypedDict(TypedDict): body_text: NotRequired[str] r"""The plain text answer to the question.""" board_id: NotRequired[int] - r"""The parent board ID of this Answer, or 0 if it's a floating Answer.""" + r"""The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted.""" audience_filters: NotRequired[List[FacetFilterTypedDict]] r"""Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search.""" added_roles: NotRequired[List[UserRoleSpecificationTypedDict]] @@ -66,8 +66,14 @@ class EditAnswerRequest(BaseModel): body_text: Annotated[Optional[str], pydantic.Field(alias="bodyText")] = None r"""The plain text answer to the question.""" - board_id: Annotated[Optional[int], pydantic.Field(alias="boardId")] = None - r"""The parent board ID of this Answer, or 0 if it's a floating Answer.""" + board_id: Annotated[ + Optional[int], + pydantic.Field( + deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible.", + alias="boardId", + ), + ] = None + r"""The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted.""" audience_filters: Annotated[ Optional[List[FacetFilter]], pydantic.Field(alias="audienceFilters") diff --git a/src/glean/api_client/models/facetfiltervalue.py b/src/glean/api_client/models/facetfiltervalue.py index 84af2821..b60f039b 100644 --- a/src/glean/api_client/models/facetfiltervalue.py +++ b/src/glean/api_client/models/facetfiltervalue.py @@ -13,6 +13,7 @@ class RelationType(str, Enum): ID_EQUALS = "ID_EQUALS" LT = "LT" GT = "GT" + NOT_EQUALS = "NOT_EQUALS" class FacetFilterValueTypedDict(TypedDict): diff --git a/src/glean/api_client/models/feedrequest.py b/src/glean/api_client/models/feedrequest.py index d9f4be0c..a4e3c1e2 100644 --- a/src/glean/api_client/models/feedrequest.py +++ b/src/glean/api_client/models/feedrequest.py @@ -26,6 +26,7 @@ class FeedRequestCategory(str, Enum): DISPLAYABLE_LIST = "DISPLAYABLE_LIST" SOCIAL_LINK = "SOCIAL_LINK" EXTERNAL_TASKS = "EXTERNAL_TASKS" + WORKFLOW_COLLECTIONS = "WORKFLOW_COLLECTIONS" ZERO_STATE_CHAT_SUGGESTION = "ZERO_STATE_CHAT_SUGGESTION" ZERO_STATE_CHAT_TOOL_SUGGESTION = "ZERO_STATE_CHAT_TOOL_SUGGESTION" ZERO_STATE_WORKFLOW_CREATED_BY_ME = "ZERO_STATE_WORKFLOW_CREATED_BY_ME" diff --git a/src/glean/api_client/models/inputoptions.py b/src/glean/api_client/models/inputoptions.py index 8d013eef..f733d9fd 100644 --- a/src/glean/api_client/models/inputoptions.py +++ b/src/glean/api_client/models/inputoptions.py @@ -23,6 +23,7 @@ class TimePeriodType(str, Enum): PAST_YEAR = "PAST_YEAR" PAST_DAY = "PAST_DAY" CUSTOM = "CUSTOM" + LAST_N_DAYS = "LAST_N_DAYS" class InputOptionsTypedDict(TypedDict): diff --git a/src/glean/api_client/models/listentitiesrequest.py b/src/glean/api_client/models/listentitiesrequest.py index 219e947e..24484f3d 100644 --- a/src/glean/api_client/models/listentitiesrequest.py +++ b/src/glean/api_client/models/listentitiesrequest.py @@ -28,6 +28,13 @@ class ListEntitiesRequestIncludeField(str, Enum): UNPROCESSED_TEAMS = "UNPROCESSED_TEAMS" +class RequestType(str, Enum): + r"""The type of request being made.""" + + STANDARD = "STANDARD" + FULL_DIRECTORY = "FULL_DIRECTORY" + + class ListEntitiesRequestTypedDict(TypedDict): filter_: NotRequired[List[FacetFilterTypedDict]] sort: NotRequired[List[SortOptionsTypedDict]] @@ -45,6 +52,8 @@ class ListEntitiesRequestTypedDict(TypedDict): r"""Pagination cursor. A previously received opaque token representing the position in the overall results at which to start.""" source: NotRequired[str] r"""A string denoting the search surface from which the endpoint is called.""" + request_type: NotRequired[RequestType] + r"""The type of request being made.""" class ListEntitiesRequest(BaseModel): @@ -79,3 +88,8 @@ class ListEntitiesRequest(BaseModel): source: Optional[str] = None r"""A string denoting the search surface from which the endpoint is called.""" + + request_type: Annotated[ + Optional[RequestType], pydantic.Field(alias="requestType") + ] = RequestType.STANDARD + r"""The type of request being made.""" diff --git a/src/glean/api_client/models/relateddocuments.py b/src/glean/api_client/models/relateddocuments.py index f775ce9c..cd8bdd7c 100644 --- a/src/glean/api_client/models/relateddocuments.py +++ b/src/glean/api_client/models/relateddocuments.py @@ -19,12 +19,14 @@ class Relation(str, Enum): ATTACHMENT = "ATTACHMENT" CANONICAL = "CANONICAL" CASE = "CASE" - CONTACT = "CONTACT" + CONTACT_LOWER = "contact" + CONTACT_UPPER = "CONTACT" CONVERSATION_MESSAGES = "CONVERSATION_MESSAGES" EXPERT = "EXPERT" FROM = "FROM" HIGHLIGHT = "HIGHLIGHT" - OPPORTUNITY = "OPPORTUNITY" + OPPORTUNITY_LOWER = "opportunity" + OPPORTUNITY_UPPER = "OPPORTUNITY" RECENT = "RECENT" SOURCE = "SOURCE" TICKET = "TICKET" diff --git a/src/glean/api_client/models/searchwarning.py b/src/glean/api_client/models/searchwarning.py index 3d775bc2..e1ff1a88 100644 --- a/src/glean/api_client/models/searchwarning.py +++ b/src/glean/api_client/models/searchwarning.py @@ -17,6 +17,7 @@ class WarningType(str, Enum): COPYPASTED_QUOTES = "COPYPASTED_QUOTES" INVALID_OPERATOR = "INVALID_OPERATOR" MAYBE_INVALID_FACET_QUERY = "MAYBE_INVALID_FACET_QUERY" + TOO_MANY_DATASOURCE_GROUPS = "TOO_MANY_DATASOURCE_GROUPS" class SearchWarningTypedDict(TypedDict): diff --git a/src/glean/api_client/models/timerange.py b/src/glean/api_client/models/timerange.py index 3a7d2489..7b703df7 100644 --- a/src/glean/api_client/models/timerange.py +++ b/src/glean/api_client/models/timerange.py @@ -13,6 +13,8 @@ class TimeRangeTypedDict(TypedDict): r"""start time of the time range, applicable for the CUSTOM type.""" end_time: NotRequired[datetime] r"""end time of the time range, applicable for the CUSTOM type.""" + last_n_days_value: NotRequired[int] + r"""The number of days to look back from the current time, applicable for the LAST_N_DAYS type.""" class TimeRange(BaseModel): @@ -21,3 +23,8 @@ class TimeRange(BaseModel): end_time: Annotated[Optional[datetime], pydantic.Field(alias="endTime")] = None r"""end time of the time range, applicable for the CUSTOM type.""" + + last_n_days_value: Annotated[ + Optional[int], pydantic.Field(alias="lastNDaysValue") + ] = None + r"""The number of days to look back from the current time, applicable for the LAST_N_DAYS type.""" diff --git a/src/glean/api_client/people.py b/src/glean/api_client/people.py index 8284dfb1..523b146f 100644 --- a/src/glean/api_client/people.py +++ b/src/glean/api_client/people.py @@ -98,26 +98,15 @@ def debug( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json(http_res.text, models.DebugUserResponse) + return utils.unmarshal_json_response(models.DebugUserResponse, http_res) if utils.match_response(http_res, ["400", "401", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def debug_async( self, @@ -207,26 +196,15 @@ async def debug_async( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json(http_res.text, models.DebugUserResponse) + return utils.unmarshal_json_response(models.DebugUserResponse, http_res) if utils.match_response(http_res, ["400", "401", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) @deprecated( "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible." @@ -310,26 +288,15 @@ def count( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetUserCountResponse) + return utils.unmarshal_json_response(models.GetUserCountResponse, http_res) if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) @deprecated( "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible." @@ -413,26 +380,15 @@ async def count_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetUserCountResponse) + return utils.unmarshal_json_response(models.GetUserCountResponse, http_res) if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def index( self, @@ -518,23 +474,12 @@ def index( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def index_async( self, @@ -620,23 +565,12 @@ async def index_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def bulk_index( self, @@ -737,23 +671,12 @@ def bulk_index( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def bulk_index_async( self, @@ -854,23 +777,12 @@ async def bulk_index_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def process_all_employees_and_teams( self, @@ -942,23 +854,12 @@ def process_all_employees_and_teams( return if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def process_all_employees_and_teams_async( self, @@ -1030,23 +931,12 @@ async def process_all_employees_and_teams_async( return if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def delete( self, @@ -1130,23 +1020,12 @@ def delete( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def delete_async( self, @@ -1230,23 +1109,12 @@ async def delete_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def index_team( self, @@ -1330,23 +1198,12 @@ def index_team( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def index_team_async( self, @@ -1430,23 +1287,12 @@ async def index_team_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def delete_team( self, @@ -1527,23 +1373,12 @@ def delete_team( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def delete_team_async( self, @@ -1624,23 +1459,12 @@ async def delete_team_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def bulk_index_teams( self, @@ -1735,23 +1559,12 @@ def bulk_index_teams( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def bulk_index_teams_async( self, @@ -1846,20 +1659,9 @@ async def bulk_index_teams_async( return if utils.match_response(http_res, ["400", "401", "409", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/pins.py b/src/glean/api_client/pins.py index 9ad98a00..42d36d07 100644 --- a/src/glean/api_client/pins.py +++ b/src/glean/api_client/pins.py @@ -95,26 +95,15 @@ def update( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.PinDocument) + return utils.unmarshal_json_response(models.PinDocument, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def update_async( self, @@ -202,26 +191,15 @@ async def update_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.PinDocument) + return utils.unmarshal_json_response(models.PinDocument, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def retrieve( self, @@ -299,26 +277,15 @@ def retrieve( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetPinResponse) + return utils.unmarshal_json_response(models.GetPinResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_async( self, @@ -396,26 +363,15 @@ async def retrieve_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetPinResponse) + return utils.unmarshal_json_response(models.GetPinResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def list( self, @@ -493,26 +449,15 @@ def list( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ListPinsResponse) + return utils.unmarshal_json_response(models.ListPinsResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def list_async( self, @@ -590,26 +535,15 @@ async def list_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ListPinsResponse) + return utils.unmarshal_json_response(models.ListPinsResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def create( self, @@ -697,26 +631,15 @@ def create( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.PinDocument) + return utils.unmarshal_json_response(models.PinDocument, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def create_async( self, @@ -804,26 +727,15 @@ async def create_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.PinDocument) + return utils.unmarshal_json_response(models.PinDocument, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def remove( self, @@ -904,23 +816,12 @@ def remove( return if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def remove_async( self, @@ -1001,20 +902,9 @@ async def remove_async( return if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/policies.py b/src/glean/api_client/policies.py index 6d4f7d09..67f36448 100644 --- a/src/glean/api_client/policies.py +++ b/src/glean/api_client/policies.py @@ -85,26 +85,15 @@ def retrieve( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetDlpReportResponse) + return utils.unmarshal_json_response(models.GetDlpReportResponse, http_res) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_async( self, @@ -182,26 +171,15 @@ async def retrieve_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.GetDlpReportResponse) + return utils.unmarshal_json_response(models.GetDlpReportResponse, http_res) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def update( self, @@ -300,26 +278,17 @@ def update( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json(http_res.text, models.UpdateDlpReportResponse) + return utils.unmarshal_json_response( + models.UpdateDlpReportResponse, http_res + ) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def update_async( self, @@ -418,26 +387,17 @@ async def update_async( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json(http_res.text, models.UpdateDlpReportResponse) + return utils.unmarshal_json_response( + models.UpdateDlpReportResponse, http_res + ) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def list( self, @@ -515,26 +475,17 @@ def list( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ListDlpReportsResponse) + return utils.unmarshal_json_response( + models.ListDlpReportsResponse, http_res + ) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def list_async( self, @@ -612,26 +563,17 @@ async def list_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ListDlpReportsResponse) + return utils.unmarshal_json_response( + models.ListDlpReportsResponse, http_res + ) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def create( self, @@ -718,26 +660,17 @@ def create( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json(http_res.text, models.CreateDlpReportResponse) + return utils.unmarshal_json_response( + models.CreateDlpReportResponse, http_res + ) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def create_async( self, @@ -824,26 +757,17 @@ async def create_async( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json(http_res.text, models.CreateDlpReportResponse) + return utils.unmarshal_json_response( + models.CreateDlpReportResponse, http_res + ) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def download( self, @@ -921,23 +845,12 @@ def download( return http_res.text if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def download_async( self, @@ -1015,20 +928,9 @@ async def download_async( return http_res.text if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/reports.py b/src/glean/api_client/reports.py index d9e9b42f..04a572ef 100644 --- a/src/glean/api_client/reports.py +++ b/src/glean/api_client/reports.py @@ -88,26 +88,17 @@ def create( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json(http_res.text, models.UpdateDlpConfigResponse) + return utils.unmarshal_json_response( + models.UpdateDlpConfigResponse, http_res + ) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def create_async( self, @@ -188,26 +179,17 @@ async def create_async( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json(http_res.text, models.UpdateDlpConfigResponse) + return utils.unmarshal_json_response( + models.UpdateDlpConfigResponse, http_res + ) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def download( self, @@ -285,23 +267,12 @@ def download( return http_res.text if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def download_async( self, @@ -379,23 +350,12 @@ async def download_async( return http_res.text if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def status( self, @@ -470,26 +430,15 @@ def status( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json(http_res.text, models.ReportStatusResponse) + return utils.unmarshal_json_response(models.ReportStatusResponse, http_res) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def status_async( self, @@ -564,23 +513,12 @@ async def status_async( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json(http_res.text, models.ReportStatusResponse) + return utils.unmarshal_json_response(models.ReportStatusResponse, http_res) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/search.py b/src/glean/api_client/search.py index 90946f03..fbca144e 100644 --- a/src/glean/api_client/search.py +++ b/src/glean/api_client/search.py @@ -147,31 +147,20 @@ def query_as_admin( response_data: Any = None if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.SearchResponse) + return utils.unmarshal_json_response(models.SearchResponse, http_res) if utils.match_response(http_res, ["403", "422"], "application/json"): - response_data = utils.unmarshal_json( - http_res.text, errors.GleanDataErrorData + response_data = utils.unmarshal_json_response( + errors.GleanDataErrorData, http_res ) - raise errors.GleanDataError(data=response_data) + raise errors.GleanDataError(response_data, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def query_as_admin_async( self, @@ -310,31 +299,20 @@ async def query_as_admin_async( response_data: Any = None if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.SearchResponse) + return utils.unmarshal_json_response(models.SearchResponse, http_res) if utils.match_response(http_res, ["403", "422"], "application/json"): - response_data = utils.unmarshal_json( - http_res.text, errors.GleanDataErrorData + response_data = utils.unmarshal_json_response( + errors.GleanDataErrorData, http_res ) - raise errors.GleanDataError(data=response_data) + raise errors.GleanDataError(response_data, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def autocomplete( self, @@ -441,26 +419,15 @@ def autocomplete( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.AutocompleteResponse) + return utils.unmarshal_json_response(models.AutocompleteResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def autocomplete_async( self, @@ -567,26 +534,15 @@ async def autocomplete_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.AutocompleteResponse) + return utils.unmarshal_json_response(models.AutocompleteResponse, http_res) if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def retrieve_feed( self, @@ -681,26 +637,15 @@ def retrieve_feed( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.FeedResponse) + return utils.unmarshal_json_response(models.FeedResponse, http_res) if utils.match_response(http_res, ["400", "401", "408", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def retrieve_feed_async( self, @@ -795,26 +740,15 @@ async def retrieve_feed_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.FeedResponse) + return utils.unmarshal_json_response(models.FeedResponse, http_res) if utils.match_response(http_res, ["400", "401", "408", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def recommendations( self, @@ -932,28 +866,17 @@ def recommendations( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ResultsResponse) + return utils.unmarshal_json_response(models.ResultsResponse, http_res) if utils.match_response(http_res, ["202", "204"], "*"): return None if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def recommendations_async( self, @@ -1071,28 +994,17 @@ async def recommendations_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ResultsResponse) + return utils.unmarshal_json_response(models.ResultsResponse, http_res) if utils.match_response(http_res, ["202", "204"], "*"): return None if utils.match_response(http_res, ["400", "401", "403", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def query( self, @@ -1231,31 +1143,20 @@ def query( response_data: Any = None if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.SearchResponse) + return utils.unmarshal_json_response(models.SearchResponse, http_res) if utils.match_response(http_res, ["403", "422"], "application/json"): - response_data = utils.unmarshal_json( - http_res.text, errors.GleanDataErrorData + response_data = utils.unmarshal_json_response( + errors.GleanDataErrorData, http_res ) - raise errors.GleanDataError(data=response_data) + raise errors.GleanDataError(response_data, http_res) if utils.match_response(http_res, ["400", "401", "408", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def query_async( self, @@ -1394,28 +1295,17 @@ async def query_async( response_data: Any = None if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.SearchResponse) + return utils.unmarshal_json_response(models.SearchResponse, http_res) if utils.match_response(http_res, ["403", "422"], "application/json"): - response_data = utils.unmarshal_json( - http_res.text, errors.GleanDataErrorData + response_data = utils.unmarshal_json_response( + errors.GleanDataErrorData, http_res ) - raise errors.GleanDataError(data=response_data) + raise errors.GleanDataError(response_data, http_res) if utils.match_response(http_res, ["400", "401", "408", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/tools.py b/src/glean/api_client/tools.py index a4cb5974..f7573aab 100644 --- a/src/glean/api_client/tools.py +++ b/src/glean/api_client/tools.py @@ -82,26 +82,15 @@ def list( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ToolsListResponse) + return utils.unmarshal_json_response(models.ToolsListResponse, http_res) if utils.match_response(http_res, ["400", "401", "404", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def list_async( self, @@ -176,26 +165,15 @@ async def list_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ToolsListResponse) + return utils.unmarshal_json_response(models.ToolsListResponse, http_res) if utils.match_response(http_res, ["400", "401", "404", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) def run( self, @@ -281,26 +259,15 @@ def run( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ToolsCallResponse) + return utils.unmarshal_json_response(models.ToolsCallResponse, http_res) if utils.match_response(http_res, ["400", "401", "404", "429", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) async def run_async( self, @@ -386,23 +353,12 @@ async def run_async( ) if utils.match_response(http_res, "200", "application/json"): - return utils.unmarshal_json(http_res.text, models.ToolsCallResponse) + return utils.unmarshal_json_response(models.ToolsCallResponse, http_res) if utils.match_response(http_res, ["400", "401", "404", "429", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) - - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) + + raise errors.GleanError("Unexpected response received", http_res) diff --git a/src/glean/api_client/utils/__init__.py b/src/glean/api_client/utils/__init__.py index 3d078198..19b0dfd6 100644 --- a/src/glean/api_client/utils/__init__.py +++ b/src/glean/api_client/utils/__init__.py @@ -29,6 +29,7 @@ marshal_json, unmarshal, unmarshal_json, + unmarshal_json_response, serialize_decimal, serialize_float, serialize_int, @@ -98,6 +99,7 @@ "template_url", "unmarshal", "unmarshal_json", + "unmarshal_json_response", "validate_decimal", "validate_const", "validate_float", @@ -152,6 +154,7 @@ "template_url": ".url", "unmarshal": ".serializers", "unmarshal_json": ".serializers", + "unmarshal_json_response": ".serializers", "validate_decimal": ".serializers", "validate_const": ".serializers", "validate_float": ".serializers", diff --git a/src/glean/api_client/utils/serializers.py b/src/glean/api_client/utils/serializers.py index 76e44d71..bc29ef86 100644 --- a/src/glean/api_client/utils/serializers.py +++ b/src/glean/api_client/utils/serializers.py @@ -4,7 +4,7 @@ import functools import json import typing -from typing import Any, Dict, List, Tuple, Union, get_args +from typing import Any, Dict, List, Optional, Tuple, Union, get_args import typing_extensions from typing_extensions import get_origin @@ -13,6 +13,7 @@ from pydantic_core import from_json from ..types.basemodel import BaseModel, Nullable, OptionalNullable, Unset +from glean.api_client import errors def serialize_decimal(as_str: bool): @@ -140,6 +141,22 @@ def unmarshal_json(raw, typ: Any) -> Any: return unmarshal(from_json(raw), typ) +def unmarshal_json_response( + typ: Any, http_res: httpx.Response, body: Optional[str] = None +) -> Any: + if body is None: + body = http_res.text + try: + return unmarshal_json(body, typ) + except Exception as e: + raise errors.ResponseValidationError( + "Response validation failed", + http_res, + e, + body, + ) from e + + def unmarshal(val, typ: Any) -> Any: unmarshaller = create_model( "Unmarshaller", @@ -192,7 +209,9 @@ def is_union(obj: object) -> bool: """ Returns True if the given object is a typing.Union or typing_extensions.Union. """ - return any(obj is typing_obj for typing_obj in _get_typing_objects_by_name_of("Union")) + return any( + obj is typing_obj for typing_obj in _get_typing_objects_by_name_of("Union") + ) def stream_to_text(stream: httpx.Response) -> str: @@ -245,4 +264,3 @@ def _get_typing_objects_by_name_of(name: str) -> Tuple[Any, ...]: f"Neither typing nor typing_extensions has an object called {name!r}" ) return result - diff --git a/src/glean/api_client/visibilityoverrides.py b/src/glean/api_client/visibilityoverrides.py index 1c53ca61..f06486d2 100644 --- a/src/glean/api_client/visibilityoverrides.py +++ b/src/glean/api_client/visibilityoverrides.py @@ -82,28 +82,17 @@ def list( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json( - http_res.text, models.GetDocumentVisibilityOverridesResponse + return utils.unmarshal_json_response( + models.GetDocumentVisibilityOverridesResponse, http_res ) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def list_async( self, @@ -178,28 +167,17 @@ async def list_async( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json( - http_res.text, models.GetDocumentVisibilityOverridesResponse + return utils.unmarshal_json_response( + models.GetDocumentVisibilityOverridesResponse, http_res ) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) def create( self, @@ -288,28 +266,17 @@ def create( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json( - http_res.text, models.UpdateDocumentVisibilityOverridesResponse + return utils.unmarshal_json_response( + models.UpdateDocumentVisibilityOverridesResponse, http_res ) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = utils.stream_to_text(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) async def create_async( self, @@ -398,25 +365,14 @@ async def create_async( ) if utils.match_response(http_res, "200", "application/json; charset=UTF-8"): - return utils.unmarshal_json( - http_res.text, models.UpdateDocumentVisibilityOverridesResponse + return utils.unmarshal_json_response( + models.UpdateDocumentVisibilityOverridesResponse, http_res ) if utils.match_response(http_res, ["403", "4XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) if utils.match_response(http_res, ["500", "5XX"], "*"): http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - "API error occurred", http_res.status_code, http_res_text, http_res - ) + raise errors.GleanError("API error occurred", http_res, http_res_text) - content_type = http_res.headers.get("Content-Type") - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.GleanError( - f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", - http_res.status_code, - http_res_text, - http_res, - ) + raise errors.GleanError("Unexpected response received", http_res) diff --git a/tests/mockserver/internal/sdk/models/components/answer.go b/tests/mockserver/internal/sdk/models/components/answer.go index 39e297a4..05fc2ed7 100644 --- a/tests/mockserver/internal/sdk/models/components/answer.go +++ b/tests/mockserver/internal/sdk/models/components/answer.go @@ -45,7 +45,9 @@ type Answer struct { QuestionVariations []string `json:"questionVariations,omitempty"` // The plain text answer to the question. BodyText *string `json:"bodyText,omitempty"` - // The parent board ID of this Answer, or 0 if it's a floating Answer. + // The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted. + // + // Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. BoardID *int64 `json:"boardId,omitempty"` // Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search. AudienceFilters []FacetFilter `json:"audienceFilters,omitempty"` diff --git a/tests/mockserver/internal/sdk/models/components/answercreationdata.go b/tests/mockserver/internal/sdk/models/components/answercreationdata.go index 779a51dd..4050d341 100644 --- a/tests/mockserver/internal/sdk/models/components/answercreationdata.go +++ b/tests/mockserver/internal/sdk/models/components/answercreationdata.go @@ -39,7 +39,9 @@ type AnswerCreationData struct { QuestionVariations []string `json:"questionVariations,omitempty"` // The plain text answer to the question. BodyText *string `json:"bodyText,omitempty"` - // The parent board ID of this Answer, or 0 if it's a floating Answer. + // The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted. + // + // Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. BoardID *int64 `json:"boardId,omitempty"` // Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search. AudienceFilters []FacetFilter `json:"audienceFilters,omitempty"` diff --git a/tests/mockserver/internal/sdk/models/components/editanswerrequest.go b/tests/mockserver/internal/sdk/models/components/editanswerrequest.go index cbb07416..cf5732f1 100644 --- a/tests/mockserver/internal/sdk/models/components/editanswerrequest.go +++ b/tests/mockserver/internal/sdk/models/components/editanswerrequest.go @@ -43,7 +43,9 @@ type EditAnswerRequest struct { QuestionVariations []string `json:"questionVariations,omitempty"` // The plain text answer to the question. BodyText *string `json:"bodyText,omitempty"` - // The parent board ID of this Answer, or 0 if it's a floating Answer. + // The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted. + // + // Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. BoardID *int64 `json:"boardId,omitempty"` // Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search. AudienceFilters []FacetFilter `json:"audienceFilters,omitempty"` diff --git a/tests/mockserver/internal/sdk/models/components/facetfiltervalue.go b/tests/mockserver/internal/sdk/models/components/facetfiltervalue.go index 79b31319..bff109f9 100644 --- a/tests/mockserver/internal/sdk/models/components/facetfiltervalue.go +++ b/tests/mockserver/internal/sdk/models/components/facetfiltervalue.go @@ -10,10 +10,11 @@ import ( type RelationType string const ( - RelationTypeEquals RelationType = "EQUALS" - RelationTypeIDEquals RelationType = "ID_EQUALS" - RelationTypeLt RelationType = "LT" - RelationTypeGt RelationType = "GT" + RelationTypeEquals RelationType = "EQUALS" + RelationTypeIDEquals RelationType = "ID_EQUALS" + RelationTypeLt RelationType = "LT" + RelationTypeGt RelationType = "GT" + RelationTypeNotEquals RelationType = "NOT_EQUALS" ) func (e RelationType) ToPointer() *RelationType { @@ -32,6 +33,8 @@ func (e *RelationType) UnmarshalJSON(data []byte) error { case "LT": fallthrough case "GT": + fallthrough + case "NOT_EQUALS": *e = RelationType(v) return nil default: diff --git a/tests/mockserver/internal/sdk/models/components/feedrequest.go b/tests/mockserver/internal/sdk/models/components/feedrequest.go index 163e42d2..bc913d44 100644 --- a/tests/mockserver/internal/sdk/models/components/feedrequest.go +++ b/tests/mockserver/internal/sdk/models/components/feedrequest.go @@ -25,6 +25,7 @@ const ( FeedRequestCategoryDisplayableList FeedRequestCategory = "DISPLAYABLE_LIST" FeedRequestCategorySocialLink FeedRequestCategory = "SOCIAL_LINK" FeedRequestCategoryExternalTasks FeedRequestCategory = "EXTERNAL_TASKS" + FeedRequestCategoryWorkflowCollections FeedRequestCategory = "WORKFLOW_COLLECTIONS" FeedRequestCategoryZeroStateChatSuggestion FeedRequestCategory = "ZERO_STATE_CHAT_SUGGESTION" FeedRequestCategoryZeroStateChatToolSuggestion FeedRequestCategory = "ZERO_STATE_CHAT_TOOL_SUGGESTION" FeedRequestCategoryZeroStateWorkflowCreatedByMe FeedRequestCategory = "ZERO_STATE_WORKFLOW_CREATED_BY_ME" @@ -72,6 +73,8 @@ func (e *FeedRequestCategory) UnmarshalJSON(data []byte) error { fallthrough case "EXTERNAL_TASKS": fallthrough + case "WORKFLOW_COLLECTIONS": + fallthrough case "ZERO_STATE_CHAT_SUGGESTION": fallthrough case "ZERO_STATE_CHAT_TOOL_SUGGESTION": diff --git a/tests/mockserver/internal/sdk/models/components/inputoptions.go b/tests/mockserver/internal/sdk/models/components/inputoptions.go index c68f47e3..51e07919 100644 --- a/tests/mockserver/internal/sdk/models/components/inputoptions.go +++ b/tests/mockserver/internal/sdk/models/components/inputoptions.go @@ -38,10 +38,11 @@ func (e *DatasourcesType) UnmarshalJSON(data []byte) error { type TimePeriodType string const ( - TimePeriodTypeAllTime TimePeriodType = "ALL_TIME" - TimePeriodTypePastYear TimePeriodType = "PAST_YEAR" - TimePeriodTypePastDay TimePeriodType = "PAST_DAY" - TimePeriodTypeCustom TimePeriodType = "CUSTOM" + TimePeriodTypeAllTime TimePeriodType = "ALL_TIME" + TimePeriodTypePastYear TimePeriodType = "PAST_YEAR" + TimePeriodTypePastDay TimePeriodType = "PAST_DAY" + TimePeriodTypeCustom TimePeriodType = "CUSTOM" + TimePeriodTypeLastNDays TimePeriodType = "LAST_N_DAYS" ) func (e TimePeriodType) ToPointer() *TimePeriodType { @@ -60,6 +61,8 @@ func (e *TimePeriodType) UnmarshalJSON(data []byte) error { case "PAST_DAY": fallthrough case "CUSTOM": + fallthrough + case "LAST_N_DAYS": *e = TimePeriodType(v) return nil default: diff --git a/tests/mockserver/internal/sdk/models/components/listentitiesrequest.go b/tests/mockserver/internal/sdk/models/components/listentitiesrequest.go index bf43970e..9e5f76d4 100644 --- a/tests/mockserver/internal/sdk/models/components/listentitiesrequest.go +++ b/tests/mockserver/internal/sdk/models/components/listentitiesrequest.go @@ -84,6 +84,33 @@ func (e *ListEntitiesRequestIncludeField) UnmarshalJSON(data []byte) error { } } +// RequestType - The type of request being made. +type RequestType string + +const ( + RequestTypeStandard RequestType = "STANDARD" + RequestTypeFullDirectory RequestType = "FULL_DIRECTORY" +) + +func (e RequestType) ToPointer() *RequestType { + return &e +} +func (e *RequestType) UnmarshalJSON(data []byte) error { + var v string + if err := json.Unmarshal(data, &v); err != nil { + return err + } + switch v { + case "STANDARD": + fallthrough + case "FULL_DIRECTORY": + *e = RequestType(v) + return nil + default: + return fmt.Errorf("invalid value for RequestType: %v", v) + } +} + type ListEntitiesRequest struct { Filter []FacetFilter `json:"filter,omitempty"` // Use EntitiesSortOrder enum for SortOptions.sortBy @@ -101,6 +128,8 @@ type ListEntitiesRequest struct { Cursor *string `json:"cursor,omitempty"` // A string denoting the search surface from which the endpoint is called. Source *string `json:"source,omitempty"` + // The type of request being made. + RequestType *RequestType `default:"STANDARD" json:"requestType"` } func (l ListEntitiesRequest) MarshalJSON() ([]byte, error) { @@ -176,3 +205,10 @@ func (o *ListEntitiesRequest) GetSource() *string { } return o.Source } + +func (o *ListEntitiesRequest) GetRequestType() *RequestType { + if o == nil { + return nil + } + return o.RequestType +} diff --git a/tests/mockserver/internal/sdk/models/components/relateddocuments.go b/tests/mockserver/internal/sdk/models/components/relateddocuments.go index 338e8429..8ba764b3 100644 --- a/tests/mockserver/internal/sdk/models/components/relateddocuments.go +++ b/tests/mockserver/internal/sdk/models/components/relateddocuments.go @@ -14,12 +14,14 @@ const ( RelationAttachment Relation = "ATTACHMENT" RelationCanonical Relation = "CANONICAL" RelationCase Relation = "CASE" - RelationContact Relation = "CONTACT" + RelationContactLower Relation = "contact" + RelationContactUpper Relation = "CONTACT" RelationConversationMessages Relation = "CONVERSATION_MESSAGES" RelationExpert Relation = "EXPERT" RelationFrom Relation = "FROM" RelationHighlight Relation = "HIGHLIGHT" - RelationOpportunity Relation = "OPPORTUNITY" + RelationOpportunityLower Relation = "opportunity" + RelationOpportunityUpper Relation = "OPPORTUNITY" RelationRecent Relation = "RECENT" RelationSource Relation = "SOURCE" RelationTicket Relation = "TICKET" @@ -42,6 +44,8 @@ func (e *Relation) UnmarshalJSON(data []byte) error { fallthrough case "CASE": fallthrough + case "contact": + fallthrough case "CONTACT": fallthrough case "CONVERSATION_MESSAGES": @@ -52,6 +56,8 @@ func (e *Relation) UnmarshalJSON(data []byte) error { fallthrough case "HIGHLIGHT": fallthrough + case "opportunity": + fallthrough case "OPPORTUNITY": fallthrough case "RECENT": diff --git a/tests/mockserver/internal/sdk/models/components/searchwarning.go b/tests/mockserver/internal/sdk/models/components/searchwarning.go index 48d20d77..131f65a7 100644 --- a/tests/mockserver/internal/sdk/models/components/searchwarning.go +++ b/tests/mockserver/internal/sdk/models/components/searchwarning.go @@ -11,12 +11,13 @@ import ( type WarningType string const ( - WarningTypeLongQuery WarningType = "LONG_QUERY" - WarningTypeQuotedPunctuation WarningType = "QUOTED_PUNCTUATION" - WarningTypePunctuationOnly WarningType = "PUNCTUATION_ONLY" - WarningTypeCopypastedQuotes WarningType = "COPYPASTED_QUOTES" - WarningTypeInvalidOperator WarningType = "INVALID_OPERATOR" - WarningTypeMaybeInvalidFacetQuery WarningType = "MAYBE_INVALID_FACET_QUERY" + WarningTypeLongQuery WarningType = "LONG_QUERY" + WarningTypeQuotedPunctuation WarningType = "QUOTED_PUNCTUATION" + WarningTypePunctuationOnly WarningType = "PUNCTUATION_ONLY" + WarningTypeCopypastedQuotes WarningType = "COPYPASTED_QUOTES" + WarningTypeInvalidOperator WarningType = "INVALID_OPERATOR" + WarningTypeMaybeInvalidFacetQuery WarningType = "MAYBE_INVALID_FACET_QUERY" + WarningTypeTooManyDatasourceGroups WarningType = "TOO_MANY_DATASOURCE_GROUPS" ) func (e WarningType) ToPointer() *WarningType { @@ -39,6 +40,8 @@ func (e *WarningType) UnmarshalJSON(data []byte) error { case "INVALID_OPERATOR": fallthrough case "MAYBE_INVALID_FACET_QUERY": + fallthrough + case "TOO_MANY_DATASOURCE_GROUPS": *e = WarningType(v) return nil default: diff --git a/tests/mockserver/internal/sdk/models/components/timerange.go b/tests/mockserver/internal/sdk/models/components/timerange.go index 1c198603..a2493b92 100644 --- a/tests/mockserver/internal/sdk/models/components/timerange.go +++ b/tests/mockserver/internal/sdk/models/components/timerange.go @@ -12,6 +12,8 @@ type TimeRange struct { StartTime *time.Time `json:"startTime,omitempty"` // end time of the time range, applicable for the CUSTOM type. EndTime *time.Time `json:"endTime,omitempty"` + // The number of days to look back from the current time, applicable for the LAST_N_DAYS type. + LastNDaysValue *int64 `json:"lastNDaysValue,omitempty"` } func (t TimeRange) MarshalJSON() ([]byte, error) { @@ -38,3 +40,10 @@ func (o *TimeRange) GetEndTime() *time.Time { } return o.EndTime } + +func (o *TimeRange) GetLastNDaysValue() *int64 { + if o == nil { + return nil + } + return o.LastNDaysValue +} diff --git a/tests/test_entities.py b/tests/test_entities.py index c670cd96..04ba72dd 100644 --- a/tests/test_entities.py +++ b/tests/test_entities.py @@ -34,6 +34,7 @@ def test_entities_listentities(): ], entity_type=models.ListEntitiesRequestEntityType.PEOPLE, page_size=100, + request_type=models.RequestType.STANDARD, ) assert res is not None From 26f2ba81adb1fa885fe031c427e8058d7e5639f4 Mon Sep 17 00:00:00 2001 From: "speakeasy-github[bot]" <128539517+speakeasy-github[bot]@users.noreply.github.com> Date: Mon, 7 Jul 2025 23:20:24 +0000 Subject: [PATCH 2/2] empty commit to trigger [run-tests] workflow