-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Adds explicit SavedObjectsRespository error type for 404 that do not originate from Elasticsearch responses #107104
Changes from 6 commits
fb9eeed
854d0b0
cf5cf75
e0886b2
2671098
e1e93eb
c7315cb
95cbf5a
a408e43
8aef363
ce70c77
9a33d69
159068b
8d14a73
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectsErrorHelpers](./kibana-plugin-core-server.savedobjectserrorhelpers.md) > [createGenericNotFoundEsUnavailableError](./kibana-plugin-core-server.savedobjectserrorhelpers.creategenericnotfoundesunavailableerror.md) | ||
|
||
## SavedObjectsErrorHelpers.createGenericNotFoundEsUnavailableError() method | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
static createGenericNotFoundEsUnavailableError(type?: string | null, id?: string | null): DecoratedError; | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| type | <code>string | null</code> | | | ||
| id | <code>string | null</code> | | | ||
|
||
<b>Returns:</b> | ||
|
||
`DecoratedError` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectsErrorHelpers](./kibana-plugin-core-server.savedobjectserrorhelpers.md) > [isNotFoundEsUnavailableError](./kibana-plugin-core-server.savedobjectserrorhelpers.isnotfoundesunavailableerror.md) | ||
|
||
## SavedObjectsErrorHelpers.isNotFoundEsUnavailableError() method | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
static isNotFoundEsUnavailableError(error: Error | DecoratedError): boolean; | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| error | <code>Error | DecoratedError</code> | | | ||
|
||
<b>Returns:</b> | ||
|
||
`boolean` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,4 +202,23 @@ export class SavedObjectsErrorHelpers { | |
public static isGeneralError(error: Error | DecoratedError) { | ||
return isSavedObjectsClientError(error) && error[code] === CODE_GENERAL_ERROR; | ||
} | ||
|
||
public static createGenericNotFoundEsUnavailableError( | ||
type: string | null = null, | ||
id: string | null = null | ||
) { | ||
const notFoundError = this.createGenericNotFoundError(type, id); | ||
return this.decorateEsUnavailableError( | ||
new Error(`${notFoundError.message}`), | ||
`x-elastic-product not present or not recognized` | ||
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. I'm not sure this is the best text string to use as a descriptor for the "missing" header. I took inspiration from the client's team but made it a lot more specific. We need to get Product's input on wording if we choose to follow this implementation. |
||
); | ||
} | ||
|
||
public static isNotFoundEsUnavailableError(error: Error | DecoratedError) { | ||
return ( | ||
isSavedObjectsClientError(error) && | ||
error[code] === CODE_ES_UNAVAILABLE && | ||
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. Specifically set a status code of 503 to indicate an ES availability error. This overrides the 404 we would otherwise have thrown. |
||
error.message.startsWith('x-elastic-product not present or not recognized:') | ||
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. Do we need 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. Nope. Good catch! |
||
); | ||
} | ||
} |
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.
Do we want to differentiate this error from
isEsUnavailableError
? I'm inclined to say that we want applications to handle this condition in the same way they would handle any other issue reaching Elasticsearch. I'm not sure if there's anything different a consumer would or can do in this case vs. any otherisEsUnavailableError
. Another benefit of using the existing error is that any existing code that is handling it will also handle this new case.Curious what @mshustov thinks as well.
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.
Agree, it's
ES server is unavailable
rather thana Kibana entity is not found
.A user reacts to them in different ways: in the case of
a Kibana entity is not found
, the user needs to adjust the request params and try again.While in the case of
ES server is unavailable
, the error is not actionable: the user needs to contact an admin to address the availability problem.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.
Initially, I did try throwing
isEsUnavailableError
but that returns a boolean, not an actualError
orDecoratedError
. If you mean that we should rather throw a decoratedEsUnavailableError
that will returntrue
on checking that the error isisEsUnavailable
, then we can do that.If I'm mis-reading the types here, please let me know!.
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.
Yeah, I was thinking about something like this. @joshdover Did you mean the same?
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 initially replied with this but then deleted it again. I'm adding it back for more context on the error that I'm using:
createGenericNotFoundEsUnavailableError
will return a 503 error that adds the message from aNotFoundError
to theEsUnavailableError
. The decorated error that's thrown will asserttrue
to a check forisEsUnavailableError
, since the latter returns aboolean
for thestatusCode
being 503.