-
Notifications
You must be signed in to change notification settings - Fork 383
Expand file tree
/
Copy pathStorageErrorFactory.ts
More file actions
891 lines (805 loc) · 22.5 KB
/
Copy pathStorageErrorFactory.ts
File metadata and controls
891 lines (805 loc) · 22.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
import StorageError from "./StorageError";
const DefaultID: string = "DefaultBlobRequestID";
/**
* A factory class maintains all Azure Storage Blob service errors.
*
* @export
* @class StorageErrorFactory
*/
export default class StorageErrorFactory {
public static getContainerNotFound(
contextID: string = DefaultID
): StorageError {
return new StorageError(
404,
"ContainerNotFound",
"The specified container does not exist.",
contextID
);
}
public static getRequestEntityTooLarge(
contextID: string = DefaultID
): StorageError {
return new StorageError(
413,
"RequestEntityTooLarge",
"The uploaded entity blob is too large.",
contextID
);
}
public static getBlockCountExceedsLimit(
contextID: string = DefaultID
): StorageError {
return new StorageError(
409,
"BlockCountExceedsLimit",
"The committed block count cannot exceed the maximum limit of 50,000 blocks.",
contextID
);
}
public static getContainerAlreadyExists(
contextID: string = DefaultID
): StorageError {
return new StorageError(
409,
"ContainerAlreadyExists",
"The specified container already exists.",
contextID
);
}
public static getBlobAlreadyExists(
contextID: string = DefaultID
): StorageError {
return new StorageError(
409,
"BlobAlreadyExists",
"The specified blob already exists.",
contextID
);
}
public static getBlobNotFound(contextID: string = DefaultID): StorageError {
return new StorageError(
404,
"BlobNotFound",
"The specified blob does not exist.",
contextID
);
}
public static ResourceNotFound(contextID: string = DefaultID): StorageError {
return new StorageError(
404,
"ResourceNotFound",
"The specified resource does not exist.",
contextID
);
}
public static getInvalidQueryParameterValue(
contextID: string = DefaultID,
parameterName?: string,
parameterValue?: string,
reason?: string
): StorageError {
const additionalMessages: {
[key: string]: string;
} = {};
if (parameterName) {
additionalMessages.QueryParameterName = parameterName;
}
if (parameterValue) {
additionalMessages.QueryParameterValue = parameterValue;
}
if (reason) {
additionalMessages.Reason = reason;
}
return new StorageError(
400,
"InvalidQueryParameterValue",
`Value for one of the query parameters specified in the request URI is invalid.`,
contextID,
additionalMessages
);
}
public static getOutOfRangeInput(
contextID: string = DefaultID,
parameterName?: string,
parameterValue?: string,
reason?: string
): StorageError {
const additionalMessages: {
[key: string]: string;
} = {};
if (parameterName) {
additionalMessages.QueryParameterName = parameterName;
}
if (parameterValue) {
additionalMessages.QueryParameterValue = parameterValue;
}
if (reason) {
additionalMessages.Reason = reason;
}
return new StorageError(
400,
"OutOfRangeInput",
`One of the request inputs is out of range.`,
contextID,
additionalMessages
);
}
public static getInvalidOperation(
contextID: string = DefaultID,
message: string = ""
): StorageError {
return new StorageError(400, "InvalidOperation", message, contextID);
}
public static getInvalidBlockList(
contextID: string = DefaultID
): StorageError {
return new StorageError(
400,
"InvalidBlockList",
"The specified block list is invalid.",
contextID
);
}
public static getInvalidAuthenticationInfo(
contextID: string = DefaultID
): StorageError {
return new StorageError(
400,
"InvalidAuthenticationInfo",
"Authentication information is not given in the correct format. Check the value of Authorization header.",
contextID
);
}
public static getMd5Mismatch(
contextID: string = DefaultID,
userSpecifiedMd5: string,
serverCalculatedMd5: string
): StorageError {
return new StorageError(
400,
"Md5Mismatch",
"The MD5 value specified in the request did not match with the MD5 value calculated by the server.",
contextID,
{
UserSpecifiedMd5: userSpecifiedMd5,
ServerCalculatedMd5: serverCalculatedMd5
}
);
}
public static getCrc64Mismatch(
contextID: string = DefaultID,
userSpecifiedCrc64: string,
serverCalculatedCrc64: string
): StorageError {
return new StorageError(
400,
"Crc64Mismatch",
"The CRC64 value specified in the request did not match with the CRC64 value calculated by the server.",
contextID,
{
UserSpecifiedCrc64: userSpecifiedCrc64,
ServerCalculatedCrc64: serverCalculatedCrc64
}
);
}
public static getBothCrc64AndMd5HeaderPresent(
contextID: string = DefaultID
): StorageError {
return new StorageError(
400,
"BothCrc64AndMd5HeaderPresent",
"Both x-ms-content-crc64 header and Content-MD5 header are present.",
contextID
);
}
public static getInvalidMd5(contextID: string = DefaultID): StorageError {
return new StorageError(
400,
"InvalidMd5",
"The MD5 value specified in the request is invalid. The MD5 value must be 128 bits and Base64-encoded.",
contextID
);
}
public static getInvalidPageRange(contextID: string): StorageError {
return new StorageError(
416,
"Requested Range Not Satisfiable",
"The page range specified is invalid.",
contextID
);
}
public static getInvalidPageRange2(contextID: string, contentRange?: string): StorageError {
let returnValue = new StorageError(
416,
"InvalidRange",
"The range specified is invalid for the current size of the resource.",
contextID
);
if (contentRange) {
returnValue.headers!["Content-Range"] = contentRange;
}
return returnValue;
}
public static getInvalidLeaseDuration(
contextID: string = DefaultID
): StorageError {
return new StorageError(
400,
"InvalidHeaderValue",
"The value for one of the HTTP headers is not in the correct format.",
contextID
);
}
public static getInvalidLeaseBreakPeriod(
contextID: string = DefaultID
): StorageError {
return new StorageError(
400,
"InvalidHeaderValue",
"The value for one of the HTTP headers is not in the correct format.",
contextID
);
}
public static getInvalidId(contextID: string): StorageError {
return new StorageError(
400,
"InvalidHeaderValue",
"The value for one of the HTTP headers is not in the correct format.",
contextID
);
}
public static getInvalidBlobOrBlock(
contextID: string = DefaultID
): StorageError {
return new StorageError(
400,
"InvalidBlobOrBlock",
"The specified blob or block content is invalid.",
contextID
);
}
public static getLeaseAlreadyPresent(
contextID: string = DefaultID
): StorageError {
return new StorageError(
409,
"LeaseAlreadyPresent",
"There is already a lease present.",
contextID
);
}
public static getLeaseIsBreakingAndCannotBeAcquired(
contextID: string = DefaultID
): StorageError {
return new StorageError(
409,
"LeaseIsBreakingAndCannotBeAcquired",
"There is already a breaking lease, and can't be acquired.",
contextID
);
}
public static getLeaseNotPresentWithLeaseOperation(
contextID: string = DefaultID
): StorageError {
return new StorageError(
409,
"LeaseNotPresentWithLeaseOperation",
"There is currently no lease on the container or blob.",
contextID
);
}
public static getLeaseIdMismatchWithLeaseOperation(
contextID: string = DefaultID
): StorageError {
return new StorageError(
409,
"LeaseIdMismatchWithLeaseOperation",
"The lease ID specified did not match the lease ID for the container or blob.",
contextID
);
}
public static getLeaseIsBrokenAndCannotBeRenewed(
contextID: string = DefaultID
): StorageError {
return new StorageError(
409,
"LeaseIsBrokenAndCannotBeRenewed",
"The lease ID matched, but the lease has been broken explicitly and cannot be renewed.",
contextID
);
}
public static getLeaseIsBreakingAndCannotBeChanged(
contextID: string = DefaultID
): StorageError {
return new StorageError(
409,
"LeaseIsBreakingAndCannotBeChanged",
"The lease ID matched, but the lease is currently in breaking state and cannot be changed.",
contextID
);
}
public static getContainerLeaseIdMissing(
contextID: string = DefaultID
): StorageError {
return new StorageError(
412,
"LeaseIdMissing",
"There is currently a lease on the container and no lease ID was specified in the request.",
contextID
);
}
public static getContainerLeaseIdMismatchWithContainerOperation(
contextID: string = DefaultID
): StorageError {
return new StorageError(
412,
"LeaseIdMismatchWithContainerOperation",
"The lease ID specified did not match the lease ID for the container.",
contextID
);
}
public static getContainerLeaseLost(
contextID: string = DefaultID
): StorageError {
return new StorageError(
412,
"LeaseNotPresentWithContainerOperation",
"A lease ID was specified, but the lease for the container has expired.",
contextID
);
}
public static getBlobLeaseIdMismatchWithLeaseOperation(
contextID: string
): StorageError {
return new StorageError(
409,
"LeaseIdMismatchWithLeaseOperation",
"The lease ID specified did not match the lease ID for the blob.",
contextID
);
}
public static getBlobLeaseNotPresentWithLeaseOperation(
contextID: string
): StorageError {
return new StorageError(
409,
"LeaseNotPresentWithLeaseOperation",
"There is currently no lease on the blob.",
contextID
);
}
// The error code/message need check with server
public static getBlobSnapshotsPresent(
contextID: string = DefaultID
): StorageError {
return new StorageError(
400,
"SnapshotsPresent",
"This operation is not permitted because the blob is snapshot.",
contextID
);
}
public static getBlobLeaseIdMissing(
contextID: string = DefaultID
): StorageError {
return new StorageError(
412,
"LeaseIdMissing",
"There is currently a lease on the blob and no lease ID was specified in the request.",
contextID
);
}
public static getBlobLeaseIdMismatchWithBlobOperation(
contextID: string = DefaultID
): StorageError {
return new StorageError(
412,
"LeaseIdMismatchWithBlobOperation",
"The lease ID specified did not match the lease ID for the blob.",
contextID
);
}
public static getBlobLeaseLost(contextID: string = DefaultID): StorageError {
return new StorageError(
412,
"LeaseNotPresentWithBlobOperation",
"A lease ID was specified, but the lease for the blob has expired.",
contextID
);
}
public static getAuthorizationFailure(contextID: string): StorageError {
return new StorageError(
403,
"AuthorizationFailure",
// tslint:disable-next-line:max-line-length
"Server failed to authenticate the request. Make sure the value of the Authorization header is formed correctly including the signature.",
contextID
);
}
public static getAuthenticationFailed(
contextID: string = DefaultID,
authenticationErrorDetail: string
): StorageError {
return new StorageError(
403,
"AuthenticationFailed",
"Server failed to authenticate the request. Make sure the value of the Authorization header is formed correctly including the signature.",
contextID,
{
AuthenticationErrorDetail: authenticationErrorDetail
}
);
}
public static getBlobInvalidBlobType(
contextID: string = DefaultID
): StorageError {
return new StorageError(
409,
"InvalidBlobType",
"The blob type is invalid for this operation.",
contextID
);
}
public static getAccessTierNotSupportedForBlobType(
contextID: string
): StorageError {
return new StorageError(
400,
"AccessTierNotSupportedForBlobType",
"The access tier is not supported for this blob type.",
contextID
);
}
public static getMultipleConditionHeadersNotSupported(
contextID: string
): StorageError {
return new StorageError(
400,
"MultipleConditionHeadersNotSupported",
"Multiple condition headers are not supported.",
contextID
);
}
public static getBlobSnapshotsPresent_hassnapshot(
contextID: string
): StorageError {
return new StorageError(
409,
"SnapshotsPresent",
"This operation is not permitted because the blob has snapshots.",
contextID
);
}
public static getBlobCannotChangeToLowerTier(
contextID: string
): StorageError {
return new StorageError(
409,
"CannotChangeToLowerTier",
"A higher blob tier has already been explicitly set.",
contextID
);
}
public static getBlobBlobTierInadequateForContentLength(
contextID: string
): StorageError {
return new StorageError(
409,
"BlobTierInadequateForContentLength",
"Specified blob tier size limit cannot be less than content length.",
contextID
);
}
public static getAuthorizationSourceIPMismatch(
contextID: string
): StorageError {
return new StorageError(
403,
"AuthorizationSourceIPMismatch",
"This request is not authorized to perform this operation using this source IP {SourceIP}.",
contextID
);
}
public static getAuthorizationProtocolMismatch(
contextID: string
): StorageError {
return new StorageError(
403,
"AuthorizationProtocolMismatch",
"This request is not authorized to perform this operation using this protocol.",
contextID
);
}
public static getAuthorizationPermissionMismatch(
contextID: string
): StorageError {
return new StorageError(
403,
"AuthorizationPermissionMismatch",
"This request is not authorized to perform this operation using this permission.",
contextID
);
}
public static getAuthorizationServiceMismatch(
contextID: string
): StorageError {
return new StorageError(
403,
"AuthorizationServiceMismatch",
"This request is not authorized to perform this operation using this service.",
contextID
);
}
public static getAuthorizationResourceTypeMismatch(
contextID: string
): StorageError {
return new StorageError(
403,
"AuthorizationResourceTypeMismatch",
"This request is not authorized to perform this operation using this resource type.",
contextID
);
}
public static getFeatureVersionMismatch(contextID: string): StorageError {
return new StorageError(
409,
"FeatureVersionMismatch",
"Stored access policy contains a permission that is not supported by this version.",
contextID
);
}
public static getCopyIdMismatch(contextID: string): StorageError {
return new StorageError(
409,
"CopyIdMismatch",
"The specified copy ID did not match the copy ID for the pending copy operation.",
contextID
);
}
public static getBothUserTagsAndSourceTagsCopyPresentException(contextID: string): StorageError {
return new StorageError(
400,
"BothUserTagsAndSourceTagsCopyPresentException",
"x-ms-tags header must not be present with x-ms-copy-source-tag-option as COPY.",
contextID
);
}
public static getNoPendingCopyOperation(contextID: string): StorageError {
return new StorageError(
409,
"NoPendingCopyOperation",
"There is currently no pending copy operation.",
contextID
);
}
public static getSnapshotsPresent(contextID: string): StorageError {
return new StorageError(
409,
"SnapshotsPresent",
"This operation is not permitted while the blob has snapshots.",
contextID
);
}
public static getConditionNotMet(contextID: string): StorageError {
return new StorageError(
412,
"ConditionNotMet",
"The condition specified using HTTP conditional header(s) is not met.",
contextID
);
}
public static getMaxBlobSizeConditionNotMet(
contextID: string = DefaultID
): StorageError {
return new StorageError(
412,
"MaxBlobSizeConditionNotMet",
"The max blob size condition specified was not met.",
contextID
);
}
public static getAppendPositionConditionNotMet(
contextID: string = DefaultID
): StorageError {
return new StorageError(
412,
"AppendPositionConditionNotMet",
"The append position condition specified was not met.",
contextID
);
}
public static getSequenceNumberConditionNotMet(
contextID: string
): StorageError {
return new StorageError(
412,
"SequenceNumberConditionNotMet",
"The condition specified using HTTP conditional header(s) is not met.",
contextID
);
}
public static getNotModified(contextID: string): StorageError {
return new StorageError(
304,
"ConditionNotMet",
"The condition specified using HTTP conditional header(s) is not met.",
contextID
);
}
public static getUnsatisfiableCondition(contextID: string): StorageError {
return new StorageError(
400,
"UnsatisfiableCondition",
"The request includes an unsatisfiable condition for this operation.",
contextID
);
}
public static getInvalidHeaderValue(
contextID: string = "",
additionalMessages?: { [key: string]: string }
): StorageError {
if (additionalMessages === undefined) {
additionalMessages = {};
}
return new StorageError(
400,
"InvalidHeaderValue",
"The value for one of the HTTP headers is not in the correct format.",
contextID,
additionalMessages
);
}
public static getInvalidAPIVersion(
contextID: string = "",
apiVersion?: string,
): StorageError {
return new StorageError(
400,
"InvalidHeaderValue",
`The API version ${apiVersion} is not supported by Azurite. Please upgrade Azurite to latest version and retry. If you are using Azurite in Visual Studio, please check you have installed latest Visual Studio patch. Azurite command line parameter \"--skipApiVersionCheck\" or Visual Studio Code configuration \"Skip Api Version Check\" can skip this error. `,
contextID
);
}
public static getBlobArchived(
contextID: string = "",
additionalMessages?: { [key: string]: string }
): StorageError {
if (additionalMessages === undefined) {
additionalMessages = {};
}
return new StorageError(
409,
"BlobArchived",
"This operation is not permitted on an archived blob.",
contextID,
additionalMessages
);
}
public static getInvalidCorsHeaderValue(
contextID: string = "",
additionalMessages?: { [key: string]: string }
): StorageError {
return new StorageError(
400,
"InvalidHeaderValue",
"A required CORS header is not present.",
contextID,
additionalMessages
);
}
public static corsPreflightFailure(
contextID: string = "",
additionalMessages?: { [key: string]: string }
): StorageError {
return new StorageError(
403,
"CorsPreflightFailure",
"CORS not enabled or no matching rule found for this request.",
contextID,
additionalMessages
);
}
public static getCannotVerifyCopySource(
contextID: string,
statusCode: number,
message: string,
additionalMessages?: { [key: string]: string }
): StorageError {
return new StorageError(
statusCode,
"CannotVerifyCopySource",
message,
contextID,
additionalMessages
);
}
public static getInvalidResourceName(contextID: string = ""): StorageError {
return new StorageError(
400,
"InvalidResourceName",
`The specified resource name contains invalid characters.`,
contextID
);
}
public static getOutOfRangeName(contextID: string = ""): StorageError {
return new StorageError(
400,
"OutOfRangeInput",
`The specified resource name length is not within the permissible limits.`,
contextID
);
}
public static getUnexpectedSyncCopyStatus(
contextID: string,
copyStatus: string
): StorageError {
return new StorageError(
409,
"UnexpectedSyncCopyStatus",
'Expected copyStatus to be "success" but got different status.',
contextID,
{ ReceivedCopyStatus: copyStatus }
);
}
public static getInvalidMetadata(contextID: string): StorageError {
return new StorageError(
400,
"InvalidMetadata",
"The metadata specified is invalid. It has characters that are not permitted.",
contextID
);
}
public static getEmptyTagName(contextID: string): StorageError {
return new StorageError(
400,
"EmptyTagName",
"The name of one of the tag key-value pairs is empty.",
contextID
);
}
public static getDuplicateTagNames(contextID: string): StorageError {
return new StorageError(
400,
"DuplicateTagNames",
"The tags specified contain duplicate names.",
contextID
);
}
public static getTagsTooLarge(contextID: string): StorageError {
return new StorageError(
400,
"TagsTooLarge",
"The tags specified exceed the maximum permissible limit.",
contextID
);
}
public static getInvalidTag(contextID: string): StorageError {
return new StorageError(
400,
"DuplicateTagNames",
"The tags specified are invalid. It contains characters that are not permitted.",
contextID
);
}
public static getInvalidXmlDocument(
contextID: string = ""
): StorageError {
return new StorageError(
400,
"InvalidXmlDocument",
`XML specified is not syntactically valid.`,
contextID
);
}
public static getBlobSealed(
contextID: string = ""
): StorageError {
return new StorageError(
409,
"BlobIsSealed",
"The specified blob is sealed, and its contents can't be modified unless the blob is re-created after a delete.",
contextID
);
}
}