forked from empowerchain/deposit-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.ts
executable file
·889 lines (750 loc) · 29.6 KB
/
client.ts
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
// Code generated by the Encore v1.4.0 client generator. DO NOT EDIT.
/* eslint-disable @typescript-eslint/no-namespace */
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* BaseURL is the base URL for calling the Encore application's API.
*/
export type BaseURL = string
export const Local: BaseURL = "http://localhost:4000"
/**
* Environment returns a BaseURL for calling the cloud environment with the given name.
*/
export function Environment(name: string): BaseURL {
return `https://${name}-deposit-pqu2.encr.app`
}
/**
* Client is an API client for the deposit-pqu2 Encore application.
*/
export default class Client {
public readonly deposit: deposit.ServiceClient
public readonly organization: organization.ServiceClient
public readonly scheme: scheme.ServiceClient
public readonly tmp: tmp.ServiceClient
/**
* @deprecated This constructor is deprecated, and you should move to using BaseURL with an Options object
*/
constructor(target: string, token?: string)
/**
* Creates a Client for calling the public and authenticated APIs of your Encore application.
*
* @param target The target which the client should be configured to use. See Local and Environment for options.
* @param options Options for the client
*/
constructor(target: BaseURL, options?: ClientOptions)
constructor(target: string | BaseURL = "prod", options?: string | ClientOptions) {
// Convert the old constructor parameters to a BaseURL object and a ClientOptions object
if (!target.startsWith("http://") && !target.startsWith("https://")) {
target = Environment(target)
}
if (typeof options === "string") {
options = { auth: options }
}
const base = new BaseClient(target, options ?? {})
this.deposit = new deposit.ServiceClient(base)
this.organization = new organization.ServiceClient(base)
this.scheme = new scheme.ServiceClient(base)
this.tmp = new tmp.ServiceClient(base)
}
}
/**
* ClientOptions allows you to override any default behaviour within the generated Encore client.
*/
export interface ClientOptions {
/**
* By default the client will use the inbuilt fetch function for making the API requests.
* however you can override it with your own implementation here if you want to run custom
* code on each API request made or response received.
*/
fetcher?: Fetcher
/**
* Allows you to set the auth token to be used for each request
* either by passing in a static token string or by passing in a function
* which returns the auth token.
*
* These tokens will be sent as bearer tokens in the Authorization header.
*/
auth?: string | AuthDataGenerator
}
export namespace commons {
export interface ItemDefinition {
materialDefinition: { [key: string]: string }
magnitude: MagnitudeType
}
export type MagnitudeType = number
export interface MassBalance {
itemDefinition: ItemDefinition
amount: number
}
export interface Reward {
type: RewardType
typeID: string
amount: number
}
export interface RewardDefinition {
itemDefinition: ItemDefinition
rewardType: RewardType
rewardTypeID: string
perItem: number
}
export type RewardType = number
}
export namespace deposit {
export interface ClaimParams {
depositID: string
userPubKey: string
}
export interface ClaimResponse {
rewards: commons.Reward[]
}
export interface CreateVoucherDefinitionParams {
organizationID: string
name: string
pictureURL: string
}
export interface Deposit {
id: string
schemeID: string
collectionPointPubKey: string
userPubKey: string
externalRef: string
createdAt: string
massBalanceDeposits: commons.MassBalance[]
claimed: boolean
}
export interface EditVoucherDefinitionParams {
voucherDefinitionID: string
name: string
pictureURL: string
}
export interface Event {
eventType: string
eventTime: string
unitName: string
numberOfUnits: number
}
export interface GetAllDepositsParams {
userPubKey: string
desc: boolean
}
export interface GetAllDepositsResponse {
deposits: Deposit[]
}
export interface GetAllVoucherDefinitionsParams {
organizationID: string
}
export interface GetAllVoucherDefinitionsResponse {
voucherDefinitions: VoucherDefinition[]
}
export interface GetAllVouchersResponse {
vouchers: VoucherResponse[]
}
export interface GetDepositByExternalRefParams {
collectionPointPubKey: string
externalRef: string
}
export interface GetDepositParams {
depositID: string
}
export interface GetHistoryParams {
userPubKey: string
}
export interface GetHistoryResponse {
events: Event[]
}
export interface GetVoucherDefinitionParams {
voucherDefinitionID: string
}
export interface GetVoucherParams {
voucherID: string
}
export interface GetVouchersForUserParams {
userPubKey: string
}
export interface GetVouchersForUserResponse {
vouchers: VoucherResponse[]
}
export interface InvalidateVoucherParams {
voucherID: string
}
export interface MakeDepositParams {
schemeID: string
massBalanceDeposits: commons.MassBalance[]
userPubKey: string
externalRef: string
}
export interface Voucher {
id: string
voucherDefinitionID: string
ownerPubKey: string
invalidated: boolean
createdAt: string
}
export interface VoucherDefinition {
id: string
organizationID: string
name: string
pictureURL: string
}
/**
* TODO: Test that voucher def gets returned everywhere
*/
export interface VoucherResponse {
voucher: Voucher
voucherDefinition: VoucherDefinition
}
export class ServiceClient {
private baseClient: BaseClient
constructor(baseClient: BaseClient) {
this.baseClient = baseClient
}
public async Claim(params: ClaimParams): Promise<ClaimResponse> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/deposit.Claim`, JSON.stringify(params))
return await resp.json() as ClaimResponse
}
public async CreateVoucherDefinition(params: CreateVoucherDefinitionParams): Promise<VoucherDefinition> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/deposit.CreateVoucherDefinition`, JSON.stringify(params))
return await resp.json() as VoucherDefinition
}
/**
* TODO: TEST AUTH
*/
public async EditVoucherDefinition(params: EditVoucherDefinitionParams): Promise<void> {
await this.baseClient.callAPI("POST", `/deposit.EditVoucherDefinition`, JSON.stringify(params))
}
public async GetAllDeposits(params: GetAllDepositsParams): Promise<GetAllDepositsResponse> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/deposit.GetAllDeposits`, JSON.stringify(params))
return await resp.json() as GetAllDepositsResponse
}
/**
* TODO: WRITE TESTS FOR SEARCH PARAMS
*/
public async GetAllVoucherDefinitions(params: GetAllVoucherDefinitionsParams): Promise<GetAllVoucherDefinitionsResponse> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/deposit.GetAllVoucherDefinitions`, JSON.stringify(params))
return await resp.json() as GetAllVoucherDefinitionsResponse
}
public async GetAllVouchers(): Promise<GetAllVouchersResponse> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/deposit.GetAllVouchers`)
return await resp.json() as GetAllVouchersResponse
}
public async GetDeposit(params: GetDepositParams): Promise<Deposit> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/deposit.GetDeposit`, JSON.stringify(params))
return await resp.json() as Deposit
}
public async GetDepositByExternalRef(params: GetDepositByExternalRefParams): Promise<Deposit> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/deposit.GetDepositByExternalRef`, JSON.stringify(params))
return await resp.json() as Deposit
}
/**
* TODO: TEST THIS
*/
public async GetHistory(params: GetHistoryParams): Promise<GetHistoryResponse> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/deposit.GetHistory`, JSON.stringify(params))
return await resp.json() as GetHistoryResponse
}
public async GetVoucher(params: GetVoucherParams): Promise<VoucherResponse> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/deposit.GetVoucher`, JSON.stringify(params))
return await resp.json() as VoucherResponse
}
public async GetVoucherDefinition(params: GetVoucherDefinitionParams): Promise<VoucherDefinition> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/deposit.GetVoucherDefinition`, JSON.stringify(params))
return await resp.json() as VoucherDefinition
}
public async GetVouchersForUser(params: GetVouchersForUserParams): Promise<GetVouchersForUserResponse> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/deposit.GetVouchersForUser`, JSON.stringify(params))
return await resp.json() as GetVouchersForUserResponse
}
public async InvalidateVoucher(params: InvalidateVoucherParams): Promise<void> {
await this.baseClient.callAPI("POST", `/deposit.InvalidateVoucher`, JSON.stringify(params))
}
public async MakeDeposit(params: MakeDepositParams): Promise<Deposit> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/deposit.MakeDeposit`, JSON.stringify(params))
return await resp.json() as Deposit
}
}
}
export namespace organization {
export interface CreateOrgParams {
id: string
name: string
signingPubKey: string
encryptionPubKey: string
}
export interface GetAllOrganizationsResponse {
organizations: Organization[]
}
export interface GetOrganizationParams {
id: string
}
export interface Organization {
id: string
name: string
signingPubKey: string
encryptionPubKey: string
}
export class ServiceClient {
private baseClient: BaseClient
constructor(baseClient: BaseClient) {
this.baseClient = baseClient
}
public async CreateOrganization(params: CreateOrgParams): Promise<Organization> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/organization.CreateOrganization`, JSON.stringify(params))
return await resp.json() as Organization
}
public async GetAllOrganizations(): Promise<GetAllOrganizationsResponse> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/organization.GetAllOrganizations`)
return await resp.json() as GetAllOrganizationsResponse
}
public async GetOrganization(params: GetOrganizationParams): Promise<Organization> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/organization.GetOrganization`, JSON.stringify(params))
return await resp.json() as Organization
}
}
}
export namespace scheme {
export interface AddCollectionPointParams {
schemeID: string
collectionPointPubKey: string
}
export interface CreateSchemeParams {
name: string
organizationID: string
rewardDefinitions: commons.RewardDefinition[]
}
export interface EditSchemeParams {
schemeID: string
rewardDefinitions: commons.RewardDefinition[]
collectionPoints: string[]
}
export interface GetAllSchemesParams {
organizationID: string
}
export interface GetAllSchemesResponse {
schemes: Scheme[]
}
export interface GetSchemeParams {
schemeID: string
}
export interface Scheme {
id: string
name: string
createdAt: string
collectionPoints: string[]
rewardDefinitions: commons.RewardDefinition[]
organizationID: string
}
export class ServiceClient {
private baseClient: BaseClient
constructor(baseClient: BaseClient) {
this.baseClient = baseClient
}
public async AddCollectionPoint(params: AddCollectionPointParams): Promise<void> {
await this.baseClient.callAPI("POST", `/scheme.AddCollectionPoint`, JSON.stringify(params))
}
public async CreateScheme(params: CreateSchemeParams): Promise<Scheme> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/scheme.CreateScheme`, JSON.stringify(params))
return await resp.json() as Scheme
}
public async EditScheme(params: EditSchemeParams): Promise<void> {
await this.baseClient.callAPI("PUT", `/scheme.EditScheme`, JSON.stringify(params))
}
/**
* TODO: WRITE TESTS FOR SEARCH PARAMS
*/
public async GetAllSchemes(params: GetAllSchemesParams): Promise<GetAllSchemesResponse> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/scheme.GetAllSchemes`, JSON.stringify(params))
return await resp.json() as GetAllSchemesResponse
}
public async GetScheme(params: GetSchemeParams): Promise<Scheme> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("POST", `/scheme.GetScheme`, JSON.stringify(params))
return await resp.json() as Scheme
}
}
}
export namespace tmp {
export interface AuthTestResponse {
pubKey: string
}
export interface GenerateKeyResponse {
publicKey: string
privateKey: string
token: string
}
export class ServiceClient {
private baseClient: BaseClient
constructor(baseClient: BaseClient) {
this.baseClient = baseClient
}
public async AuthTest(): Promise<AuthTestResponse> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("GET", `/tmp.AuthTest`)
return await resp.json() as AuthTestResponse
}
public async GenerateKey(): Promise<GenerateKeyResponse> {
// Now make the actual call to the API
const resp = await this.baseClient.callAPI("GET", `/tmp.GenerateKey`)
return await resp.json() as GenerateKeyResponse
}
public async StatusTest(): Promise<void> {
await this.baseClient.callAPI("GET", `/tmp.StatusTest`)
}
}
}
function encodeQuery(parts: Record<string, string | string[]>): string {
const pairs : string[] = []
for (const key in parts) {
const val = (Array.isArray(parts[key]) ? parts[key] : [parts[key]]) as string[]
for (const v of val) {
pairs.push(`${key}=${encodeURIComponent(v)}`)
}
}
return pairs.join("&")
}
// CallParameters is the type of the parameters to a method call, but require headers to be a Record type
type CallParameters = Omit<RequestInit, "method" | "body"> & {
/** Any headers to be sent with the request */
headers?: Record<string, string>;
/** Any query parameters to be sent with the request */
query?: Record<string, string | string[]>
}
// AuthDataGenerator is a function that returns a new instance of the authentication data required by this API
export type AuthDataGenerator = () => (string | undefined)
// A fetcher is the prototype for the inbuilt Fetch function
export type Fetcher = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
class BaseClient {
readonly baseURL: string
readonly fetcher: Fetcher
readonly headers: Record<string, string>
readonly authGenerator?: AuthDataGenerator
constructor(baseURL: string, options: ClientOptions) {
this.baseURL = baseURL
this.headers = {
"Content-Type": "application/json",
"User-Agent": "deposit-pqu2-Generated-TS-Client (Encore/v1.4.0)",
}
// Setup what fetch function we'll be using in the base client
if (options.fetcher !== undefined) {
this.fetcher = options.fetcher
} else {
this.fetcher = fetch
}
// Setup an authentication data generator using the auth data token option
if (options.auth !== undefined) {
const auth = options.auth
if (typeof auth === "function") {
this.authGenerator = auth
} else {
this.authGenerator = () => auth
}
}
}
// callAPI is used by each generated API method to actually make the request
public async callAPI(method: string, path: string, body?: BodyInit, params?: CallParameters): Promise<Response> {
// eslint-disable-next-line prefer-const
let { query, ...rest } = params ?? {}
const init = {
...rest,
method,
body: body ?? null,
}
// Merge our headers with any predefined headers
init.headers = {...this.headers, ...init.headers}
// If authorization data generator is present, call it and add the returned data to the request
let authData: string | undefined
if (this.authGenerator) {
authData = this.authGenerator()
}
// If we now have authentication data, add it to the request
if (authData) {
init.headers["Authorization"] = "Bearer " + authData
}
// Make the actual request
const queryString = query ? '?' + encodeQuery(query) : ''
const response = await this.fetcher(this.baseURL+path+queryString, init)
// handle any error responses
if (!response.ok) {
// try and get the error message from the response body
let body: APIErrorResponse = { code: ErrCode.Unknown, message: `request failed: status ${response.status}` }
// if we can get the structured error we should, otherwise give a best effort
try {
const text = await response.text()
try {
const jsonBody = JSON.parse(text)
if (isAPIErrorResponse(jsonBody)) {
body = jsonBody
} else {
body.message += ": " + JSON.stringify(jsonBody)
}
} catch {
body.message += ": " + text
}
} catch (e) {
// otherwise we just append the text to the error message
body.message += ": " + String(e)
}
throw new APIError(response.status, body)
}
return response
}
}
/**
* APIErrorDetails represents the response from an Encore API in the case of an error
*/
interface APIErrorResponse {
code: ErrCode
message: string
details?: any
}
function isAPIErrorResponse(err: any): err is APIErrorResponse {
return (
err !== undefined && err !== null &&
isErrCode(err.code) &&
typeof(err.message) === "string" &&
(err.details === undefined || err.details === null || typeof(err.details) === "object")
)
}
function isErrCode(code: any): code is ErrCode {
return code !== undefined && Object.values(ErrCode).includes(code)
}
/**
* APIError represents a structured error as returned from an Encore application.
*/
export class APIError extends Error {
/**
* The HTTP status code associated with the error.
*/
public readonly status: number
/**
* The Encore error code
*/
public readonly code: ErrCode
/**
* The error details
*/
public readonly details?: any
constructor(status: number, response: APIErrorResponse) {
// extending errors causes issues after you construct them, unless you apply the following fixes
super(response.message);
// set error name as constructor name, make it not enumerable to keep native Error behavior
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new.target#new.target_in_constructors
Object.defineProperty(this, 'name', {
value: 'APIError',
enumerable: false,
configurable: true,
})
// fix the prototype chain
if ((Object as any).setPrototypeOf == undefined) {
(this as any).__proto__ = APIError.prototype
} else {
Object.setPrototypeOf(this, APIError.prototype);
}
// capture a stack trace
if ((Error as any).captureStackTrace !== undefined) {
(Error as any).captureStackTrace(this, this.constructor);
}
this.status = status
this.code = response.code
this.details = response.details
}
}
/**
* Typeguard allowing use of an APIError's fields'
*/
export function isAPIError(err: any): err is APIError {
return err instanceof APIError;
}
export enum ErrCode {
/**
* OK indicates the operation was successful.
*/
OK = "ok",
/**
* Canceled indicates the operation was canceled (typically by the caller).
*
* Encore will generate this error code when cancellation is requested.
*/
Canceled = "canceled",
/**
* Unknown error. An example of where this error may be returned is
* if a Status value received from another address space belongs to
* an error-space that is not known in this address space. Also
* errors raised by APIs that do not return enough error information
* may be converted to this error.
*
* Encore will generate this error code in the above two mentioned cases.
*/
Unknown = "unknown",
/**
* InvalidArgument indicates client specified an invalid argument.
* Note that this differs from FailedPrecondition. It indicates arguments
* that are problematic regardless of the state of the system
* (e.g., a malformed file name).
*
* This error code will not be generated by the gRPC framework.
*/
InvalidArgument = "invalid_argument",
/**
* DeadlineExceeded means operation expired before completion.
* For operations that change the state of the system, this error may be
* returned even if the operation has completed successfully. For
* example, a successful response from a server could have been delayed
* long enough for the deadline to expire.
*
* The gRPC framework will generate this error code when the deadline is
* exceeded.
*/
DeadlineExceeded = "deadline_exceeded",
/**
* NotFound means some requested entity (e.g., file or directory) was
* not found.
*
* This error code will not be generated by the gRPC framework.
*/
NotFound = "not_found",
/**
* AlreadyExists means an attempt to create an entity failed because one
* already exists.
*
* This error code will not be generated by the gRPC framework.
*/
AlreadyExists = "already_exists",
/**
* PermissionDenied indicates the caller does not have permission to
* execute the specified operation. It must not be used for rejections
* caused by exhausting some resource (use ResourceExhausted
* instead for those errors). It must not be
* used if the caller cannot be identified (use Unauthenticated
* instead for those errors).
*
* This error code will not be generated by the gRPC core framework,
* but expect authentication middleware to use it.
*/
PermissionDenied = "permission_denied",
/**
* ResourceExhausted indicates some resource has been exhausted, perhaps
* a per-user quota, or perhaps the entire file system is out of space.
*
* This error code will be generated by the gRPC framework in
* out-of-memory and server overload situations, or when a message is
* larger than the configured maximum size.
*/
ResourceExhausted = "resource_exhausted",
/**
* FailedPrecondition indicates operation was rejected because the
* system is not in a state required for the operation's execution.
* For example, directory to be deleted may be non-empty, an rmdir
* operation is applied to a non-directory, etc.
*
* A litmus test that may help a service implementor in deciding
* between FailedPrecondition, Aborted, and Unavailable:
* (a) Use Unavailable if the client can retry just the failing call.
* (b) Use Aborted if the client should retry at a higher-level
* (e.g., restarting a read-modify-write sequence).
* (c) Use FailedPrecondition if the client should not retry until
* the system state has been explicitly fixed. E.g., if an "rmdir"
* fails because the directory is non-empty, FailedPrecondition
* should be returned since the client should not retry unless
* they have first fixed up the directory by deleting files from it.
* (d) Use FailedPrecondition if the client performs conditional
* REST Get/Update/Delete on a resource and the resource on the
* server does not match the condition. E.g., conflicting
* read-modify-write on the same resource.
*
* This error code will not be generated by the gRPC framework.
*/
FailedPrecondition = "failed_precondition",
/**
* Aborted indicates the operation was aborted, typically due to a
* concurrency issue like sequencer check failures, transaction aborts,
* etc.
*
* See litmus test above for deciding between FailedPrecondition,
* Aborted, and Unavailable.
*/
Aborted = "aborted",
/**
* OutOfRange means operation was attempted past the valid range.
* E.g., seeking or reading past end of file.
*
* Unlike InvalidArgument, this error indicates a problem that may
* be fixed if the system state changes. For example, a 32-bit file
* system will generate InvalidArgument if asked to read at an
* offset that is not in the range [0,2^32-1], but it will generate
* OutOfRange if asked to read from an offset past the current
* file size.
*
* There is a fair bit of overlap between FailedPrecondition and
* OutOfRange. We recommend using OutOfRange (the more specific
* error) when it applies so that callers who are iterating through
* a space can easily look for an OutOfRange error to detect when
* they are done.
*
* This error code will not be generated by the gRPC framework.
*/
OutOfRange = "out_of_range",
/**
* Unimplemented indicates operation is not implemented or not
* supported/enabled in this service.
*
* This error code will be generated by the gRPC framework. Most
* commonly, you will see this error code when a method implementation
* is missing on the server. It can also be generated for unknown
* compression algorithms or a disagreement as to whether an RPC should
* be streaming.
*/
Unimplemented = "unimplemented",
/**
* Internal errors. Means some invariants expected by underlying
* system has been broken. If you see one of these errors,
* something is very broken.
*
* This error code will be generated by the gRPC framework in several
* internal error conditions.
*/
Internal = "internal",
/**
* Unavailable indicates the service is currently unavailable.
* This is a most likely a transient condition and may be corrected
* by retrying with a backoff. Note that it is not always safe to retry
* non-idempotent operations.
*
* See litmus test above for deciding between FailedPrecondition,
* Aborted, and Unavailable.
*
* This error code will be generated by the gRPC framework during
* abrupt shutdown of a server process or network connection.
*/
Unavailable = "unavailable",
/**
* DataLoss indicates unrecoverable data loss or corruption.
*
* This error code will not be generated by the gRPC framework.
*/
DataLoss = "data_loss",
/**
* Unauthenticated indicates the request does not have valid
* authentication credentials for the operation.
*
* The gRPC framework will generate this error code when the
* authentication metadata is invalid or a Credentials callback fails,
* but also expect authentication middleware to generate it.
*/
Unauthenticated = "unauthenticated",
}