-
Notifications
You must be signed in to change notification settings - Fork 17
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
Provide dedicated error message for when a token is marked as disabled due to inactivity #2084
Conversation
…due to inactivity
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Files |
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.
Left some minor wording changes, otherwise this is great.
src/lib/api.ts
Outdated
); | ||
let message = | ||
'You are unauthorized to perform this request, please logout with `vip logout` then try again.'; | ||
if ( 'result' in networkError && networkError.result?.code === 'token-disabled-inactivity' ) { |
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.
Is the in
check actually necessary since we have ?
?
if ( 'result' in networkError && networkError.result?.code === 'token-disabled-inactivity' ) { | |
if ( networkError.result?.code === 'token-disabled-inactivity' ) { |
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.
@mjangda We need the result in
to make TS aware we're using the class ServerError
instead of ServerParseError
from the Apollo Client.
import { ServerError } from '../utils';
import { ServerParseError } from '../http';
export interface ErrorResponse {
graphQLErrors?: ReadonlyArray<GraphQLError>;
networkError?: Error | ServerError | ServerParseError;
[....]
}
If we use your code the type checker will error out with
Property 'result' does not exist on type 'ServerParseError'.
42 if ( networkError.result?.code === 'token-disabled-inactivity' ) {
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.
Interesting, thank you for explaining that.
Maybe we should make the check more obvious to indicate that?
if ( 'result' in networkError && networkError.result?.code === 'token-disabled-inactivity' ) { | |
if ( networkError instanceof ServerError && networkError.result?.code === 'token-disabled-inactivity' ) { |
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.
This doesn't work either (I tested before landing with the result in
) since we're checking against a type (ServerError) and not a class.
> tsc
src/lib/api.ts:43:33 - error TS2359: The right-hand side of an 'instanceof' expression must be either of type 'any', a class, function, or other type assignable to the 'Function' interface type, or an object type with a 'Symbol.hasInstance' method.
43 if ( networkError instanceof ServerError && networkError.result?.code === 'token-disabled-inactivity' ) {
~~~~~~~~~~~
src/lib/api.ts:43:61 - error TS2339: Property 'result' does not exist on type 'ServerError | ServerParseError'.
Property 'result' does not exist on type 'ServerParseError'.
43 if ( networkError instanceof ServerError && networkError.result?.code === 'token-disabled-inactivity' ) {
~~~~~~
Found 2 errors in the same file, starting at: src/lib/api.ts:43
What we can do, if we want to improve the readability, is to have a isServerError
function with the same check @mjangda
something like
function isServerError(networkError){
return 'result' in networkError;
}
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.
Even more interesting :)
I think the readability would be nice improvement but it's very minor.
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.
Added in 0d8eefe . For future reference here's also the docs around using in
operator narrowing: https://www.typescriptlang.org/docs/handbook/2/narrowing.html#the-in-operator-narrowing
Co-authored-by: Mohammad Jangda <[email protected]>
Co-authored-by: Mohammad Jangda <[email protected]>
…Error is a ServerError type
Quality Gate passedIssues Measures |
Description
This PR adds support for the new unauthorized error for inactive tokens.
Changelog Description
Adds support for the disabled token due to inactivity error so that it shows a dedicated error message.
Pull request checklist
New release checklist
Steps to Test
npm run build
VIP_PROXY="" API_HOST=http://localhost:4000 node ./dist/bin/vip app list
with a token that is disabled due to inactivityvip logout
then try again.'