Skip to content

Commit

Permalink
console: Rollback classes which are not components
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelJankoski committed Nov 17, 2023
1 parent bf36a53 commit 0e693a8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
4 changes: 2 additions & 2 deletions pkg/webui/lib/access-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export default fetchToken => {
const response = await fetchToken()
const token = response.data
if (!isPlainObject(token) || !('access_token' in token)) {
throw TokenError('Received invalid token')
throw new TokenError('Received invalid token')
}

cache.set('accessToken', token)

return token
} catch (error) {
throw TokenError('Could not fetch token', error)
throw new TokenError('Could not fetch token', error)
} finally {
finishedRetrieval = true
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/webui/lib/errors/custom-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

/* eslint-disable import/prefer-default-export */

export const TokenError = (message, cause) => {
const error = new Error(message)
error.cause = cause
error.name = 'TokenError'
return error
export class TokenError extends Error {
constructor(message, cause) {
super(message)
this.cause = cause
this.name = 'TokenError'
}
}
6 changes: 3 additions & 3 deletions pkg/webui/lib/errors/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ const emptyError = {}
const undefinedError = undefined
const errorInstance = new Error('There was an unknown error')
const networkError = new Error('Network Error')
const tokenTimeoutError = TokenError('Could not fetch token', timeoutError)
const tokenNetworkError = TokenError('Could not fetch token', networkError)
const tokenError = TokenError('Token error', backendErrorWithDetails)
const tokenTimeoutError = new TokenError('Could not fetch token', timeoutError)
const tokenNetworkError = new TokenError('Could not fetch token', networkError)
const tokenError = new TokenError('Token error', backendErrorWithDetails)

describe('Get Sentry error title', () => {
it('retrieves the right error title', () => {
Expand Down
35 changes: 19 additions & 16 deletions pkg/webui/lib/yup.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,27 @@ const StringSchema = Yup.string
* schema type. It transforms the value to `null` if it is empty and skips
* validation.
*/
const NullableStringSchemaType = () => {
const self = new StringSchema()

self.withMutation(() => {
self
.transform(value => {
if (self.isType(value) && Boolean(value)) {
return value
}
return null
})
.nullable()
})

return self
class NullableStringSchemaType extends StringSchema {
constructor() {
super()

const self = this

self.withMutation(() => {
self
.transform(value => {
if (self.isType(value) && Boolean(value)) {
return value
}

return null
})
.nullable()
})
}
}

const nullableString = () => NullableStringSchemaType()
const nullableString = () => new NullableStringSchemaType()

const passValues = message => values => ({
message,
Expand Down

0 comments on commit 0e693a8

Please sign in to comment.