Skip to content

Commit 96c3e53

Browse files
authored
chore(errors): simplify the precondition message (#57)
1 parent c9933d4 commit 96c3e53

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

packages/clients/src/scw/errors/standard/__tests__/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ describe('PreconditionFailedError', () => {
279279
precondition: 'unknown_precondition',
280280
type: 'precondition_failed',
281281
}).toString(),
282-
).toBe('PreconditionFailedError: precondition failed: unknown precondition')
282+
).toBe('PreconditionFailedError: precondition failed: unknown_precondition')
283283
})
284284

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

@@ -303,7 +303,7 @@ describe('PreconditionFailedError', () => {
303303
type: 'precondition_failed',
304304
}).toString(),
305305
).toBe(
306-
'PreconditionFailedError: precondition failed: attribute must be set',
306+
'PreconditionFailedError: precondition failed: attribute_must_be_set',
307307
)
308308
})
309309

@@ -314,7 +314,9 @@ describe('PreconditionFailedError', () => {
314314
precondition: 'wrong_precondition_key',
315315
type: 'precondition_failed',
316316
}).toString(),
317-
).toBe('PreconditionFailedError: precondition failed: ')
317+
).toBe(
318+
'PreconditionFailedError: precondition failed: wrong_precondition_key',
319+
)
318320
})
319321

320322
it(`doesn't parse invalid input`, () => {

packages/clients/src/scw/errors/standard/precondition-failed-error.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,12 @@ import { ScalewayError } from '../scw-error'
1111
* @internal
1212
*/
1313
const buildMessage = (precondition: string, helpMessage: string): string => {
14-
let message: string
15-
switch (precondition) {
16-
case 'unknown_precondition':
17-
message = 'unknown precondition'
18-
break
19-
case 'resource_still_in_use':
20-
message = 'resource is still in use'
21-
break
22-
case 'attribute_must_be_set':
23-
message = 'attribute must be set'
24-
break
25-
default:
26-
message = ''
27-
}
14+
let message = `precondition failed: ${precondition}`
2815
if (typeof helpMessage === 'string' && helpMessage.length > 0) {
2916
message = message.concat(', ', helpMessage)
3017
}
3118

32-
return `precondition failed: ${message}`
19+
return message
3320
}
3421

3522
/**

0 commit comments

Comments
 (0)