-
Notifications
You must be signed in to change notification settings - Fork 5
fix: improve Genie API error messages for access denied scenarios #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,14 @@ const Time = SDK.Time ?? (SDK as any).default.Time; | |
|
|
||
| const logger = createLogger("connectors:genie"); | ||
|
|
||
| const GenieErrors = { | ||
| SPACE_ACCESS_DENIED: "You don't have access to this Genie Space.", | ||
| TABLE_PERMISSIONS: | ||
| "You may not have access to the data tables. Please verify your table permissions.", | ||
| REQUEST_FAILED: "Genie request failed", | ||
| QUERY_RESULT_FAILED: "Failed to fetch query result", | ||
| } as const; | ||
|
|
||
| type CreateMessageWaiter = Waiter<GenieMessage, GenieMessage>; | ||
|
|
||
| export interface GenieConnectorConfig { | ||
|
|
@@ -54,6 +62,23 @@ function toMessageResponse(message: GenieMessage): GenieMessageResponse { | |
| }; | ||
| } | ||
|
|
||
| function classifyGenieError(error: unknown): string { | ||
| const message = error instanceof Error ? error.message : String(error); | ||
|
|
||
| if (message.includes("RESOURCE_DOES_NOT_EXIST")) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can have an object which defines what's the API returns and what we display? WDYT? It will be easier to maintain it for future.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, I defined these in an object |
||
| return GenieErrors.SPACE_ACCESS_DENIED; | ||
| } | ||
|
|
||
| if ( | ||
| message.includes("failed to reach COMPLETED state") && | ||
| message.includes("FAILED") | ||
| ) { | ||
| return GenieErrors.TABLE_PERMISSIONS; | ||
| } | ||
|
|
||
| return message || GenieErrors.REQUEST_FAILED; | ||
| } | ||
|
|
||
| export class GenieConnector { | ||
| private readonly config: Required<GenieConnectorConfig>; | ||
|
|
||
|
|
@@ -206,11 +231,13 @@ export class GenieConnector { | |
| messageResponse, | ||
| ); | ||
| } catch (error) { | ||
| logger.error("Genie message error: %O", error); | ||
| yield { | ||
| type: "error", | ||
| error: error instanceof Error ? error.message : "Genie request failed", | ||
| }; | ||
| logger.error( | ||
| "Genie message error (spaceId=%s, conversationId=%s): %O", | ||
| spaceId, | ||
| conversationId ?? "new", | ||
| error, | ||
| ); | ||
| yield { type: "error", error: classifyGenieError(error) }; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -248,7 +275,7 @@ export class GenieConnector { | |
| ); | ||
| yield { | ||
| type: "error", | ||
| error: `Failed to fetch query result for attachment ${att.attachmentId}`, | ||
| error: `${GenieErrors.QUERY_RESULT_FAILED} for attachment ${att.attachmentId}`, | ||
| }; | ||
| } | ||
| } | ||
|
|
@@ -324,20 +351,19 @@ export class GenieConnector { | |
| error: | ||
| result.reason instanceof Error | ||
| ? result.reason.message | ||
| : "Failed to fetch query result", | ||
| : GenieErrors.QUERY_RESULT_FAILED, | ||
| }; | ||
| } | ||
| } | ||
| } | ||
| } catch (error) { | ||
| logger.error("Genie getConversation error: %O", error); | ||
| yield { | ||
| type: "error", | ||
| error: | ||
| error instanceof Error | ||
| ? error.message | ||
| : "Failed to fetch conversation", | ||
| }; | ||
| logger.error( | ||
| "Genie getConversation error (spaceId=%s, conversationId=%s): %O", | ||
| spaceId, | ||
| conversationId, | ||
| error, | ||
| ); | ||
| yield { type: "error", error: classifyGenieError(error) }; | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General question: maybe it's worth to reach to Genie Team and ask for API extension in case of error responses? WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reached out to them to share our problem and ask if something could be done. Although I haven't received a response yet, I doubt they will be able to implement anything on their side on the short-term, so maybe we can start with this, and move forward with a better solution