Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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