Skip to content

Commit

Permalink
chore(errors): simplify the precondition message (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzius authored Aug 17, 2022
1 parent c9933d4 commit 96c3e53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
10 changes: 6 additions & 4 deletions packages/clients/src/scw/errors/standard/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ describe('PreconditionFailedError', () => {
precondition: 'unknown_precondition',
type: 'precondition_failed',
}).toString(),
).toBe('PreconditionFailedError: precondition failed: unknown precondition')
).toBe('PreconditionFailedError: precondition failed: unknown_precondition')
})

it(`parses a valid input for precondition precondition_failed`, () => {
Expand All @@ -291,7 +291,7 @@ describe('PreconditionFailedError', () => {
type: 'precondition_failed',
}).toString(),
).toBe(
'PreconditionFailedError: precondition failed: resource is still in use, All servers must be removed from the private network before deleting it.',
'PreconditionFailedError: precondition failed: resource_still_in_use, All servers must be removed from the private network before deleting it.',
)
})

Expand All @@ -303,7 +303,7 @@ describe('PreconditionFailedError', () => {
type: 'precondition_failed',
}).toString(),
).toBe(
'PreconditionFailedError: precondition failed: attribute must be set',
'PreconditionFailedError: precondition failed: attribute_must_be_set',
)
})

Expand All @@ -314,7 +314,9 @@ describe('PreconditionFailedError', () => {
precondition: 'wrong_precondition_key',
type: 'precondition_failed',
}).toString(),
).toBe('PreconditionFailedError: precondition failed: ')
).toBe(
'PreconditionFailedError: precondition failed: wrong_precondition_key',
)
})

it(`doesn't parse invalid input`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,12 @@ import { ScalewayError } from '../scw-error'
* @internal
*/
const buildMessage = (precondition: string, helpMessage: string): string => {
let message: string
switch (precondition) {
case 'unknown_precondition':
message = 'unknown precondition'
break
case 'resource_still_in_use':
message = 'resource is still in use'
break
case 'attribute_must_be_set':
message = 'attribute must be set'
break
default:
message = ''
}
let message = `precondition failed: ${precondition}`
if (typeof helpMessage === 'string' && helpMessage.length > 0) {
message = message.concat(', ', helpMessage)
}

return `precondition failed: ${message}`
return message
}

/**
Expand Down

0 comments on commit 96c3e53

Please sign in to comment.