Skip to content

Commit 1b3931a

Browse files
feat: add methods from gax to cache proto root and process custom error details (#2330)
* feat: add methods from gax to cache proto root and process custom error details fix: distinguish plural and singular path templates PiperOrigin-RevId: 772168312 Source-Link: googleapis/googleapis@873d84e Source-Link: googleapis/googleapis-gen@f448c1b Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZjQ0OGMxYjRlYWFhNWZkYzcwMjFhNjgyMDY4YzMxM2Q2ZjJmMTA0YSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: alkatrivedi <[email protected]>
1 parent 2a6af4c commit 1b3931a

File tree

4 files changed

+601
-41
lines changed

4 files changed

+601
-41
lines changed

src/v1/database_admin_client.ts

Lines changed: 240 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import type {
3131
import {Transform} from 'stream';
3232
import * as protos from '../../protos/protos';
3333
import jsonProtos = require('../../protos/protos.json');
34-
import {loggingUtils as logging} from 'google-gax';
34+
import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax';
3535

3636
/**
3737
* Client JSON configuration object, loaded from
@@ -267,7 +267,7 @@ export class DatabaseAdminClient {
267267
),
268268
};
269269

270-
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
270+
const protoFilesRoot = this._gaxModule.protobufFromJSON(jsonProtos);
271271
// This API contains "long-running operations", which return a
272272
// an Operation object that allows for tracking of the operation,
273273
// rather than holding a request open.
@@ -710,7 +710,23 @@ export class DatabaseAdminClient {
710710
this._log.info('getDatabase response %j', response);
711711
return [response, options, rawResponse];
712712
},
713-
);
713+
)
714+
.catch((error: any) => {
715+
if (
716+
error &&
717+
'statusDetails' in error &&
718+
error.statusDetails instanceof Array
719+
) {
720+
const protos = this._gaxModule.protobuf.Root.fromJSON(
721+
jsonProtos,
722+
) as unknown as gax.protobuf.Type;
723+
error.statusDetails = decodeAnyProtosInArray(
724+
error.statusDetails,
725+
protos,
726+
);
727+
}
728+
throw error;
729+
});
714730
}
715731
/**
716732
* Drops (aka deletes) a Cloud Spanner database.
@@ -833,7 +849,23 @@ export class DatabaseAdminClient {
833849
this._log.info('dropDatabase response %j', response);
834850
return [response, options, rawResponse];
835851
},
836-
);
852+
)
853+
.catch((error: any) => {
854+
if (
855+
error &&
856+
'statusDetails' in error &&
857+
error.statusDetails instanceof Array
858+
) {
859+
const protos = this._gaxModule.protobuf.Root.fromJSON(
860+
jsonProtos,
861+
) as unknown as gax.protobuf.Type;
862+
error.statusDetails = decodeAnyProtosInArray(
863+
error.statusDetails,
864+
protos,
865+
);
866+
}
867+
throw error;
868+
});
837869
}
838870
/**
839871
* Returns the schema of a Cloud Spanner database as a list of formatted
@@ -962,7 +994,23 @@ export class DatabaseAdminClient {
962994
this._log.info('getDatabaseDdl response %j', response);
963995
return [response, options, rawResponse];
964996
},
965-
);
997+
)
998+
.catch((error: any) => {
999+
if (
1000+
error &&
1001+
'statusDetails' in error &&
1002+
error.statusDetails instanceof Array
1003+
) {
1004+
const protos = this._gaxModule.protobuf.Root.fromJSON(
1005+
jsonProtos,
1006+
) as unknown as gax.protobuf.Type;
1007+
error.statusDetails = decodeAnyProtosInArray(
1008+
error.statusDetails,
1009+
protos,
1010+
);
1011+
}
1012+
throw error;
1013+
});
9661014
}
9671015
/**
9681016
* Sets the access control policy on a database or backup resource.
@@ -1086,7 +1134,23 @@ export class DatabaseAdminClient {
10861134
this._log.info('setIamPolicy response %j', response);
10871135
return [response, options, rawResponse];
10881136
},
1089-
);
1137+
)
1138+
.catch((error: any) => {
1139+
if (
1140+
error &&
1141+
'statusDetails' in error &&
1142+
error.statusDetails instanceof Array
1143+
) {
1144+
const protos = this._gaxModule.protobuf.Root.fromJSON(
1145+
jsonProtos,
1146+
) as unknown as gax.protobuf.Type;
1147+
error.statusDetails = decodeAnyProtosInArray(
1148+
error.statusDetails,
1149+
protos,
1150+
);
1151+
}
1152+
throw error;
1153+
});
10901154
}
10911155
/**
10921156
* Gets the access control policy for a database or backup resource.
@@ -1203,7 +1267,23 @@ export class DatabaseAdminClient {
12031267
this._log.info('getIamPolicy response %j', response);
12041268
return [response, options, rawResponse];
12051269
},
1206-
);
1270+
)
1271+
.catch((error: any) => {
1272+
if (
1273+
error &&
1274+
'statusDetails' in error &&
1275+
error.statusDetails instanceof Array
1276+
) {
1277+
const protos = this._gaxModule.protobuf.Root.fromJSON(
1278+
jsonProtos,
1279+
) as unknown as gax.protobuf.Type;
1280+
error.statusDetails = decodeAnyProtosInArray(
1281+
error.statusDetails,
1282+
protos,
1283+
);
1284+
}
1285+
throw error;
1286+
});
12071287
}
12081288
/**
12091289
* Returns permissions that the caller has on the specified database or backup
@@ -1324,7 +1404,23 @@ export class DatabaseAdminClient {
13241404
this._log.info('testIamPermissions response %j', response);
13251405
return [response, options, rawResponse];
13261406
},
1327-
);
1407+
)
1408+
.catch((error: any) => {
1409+
if (
1410+
error &&
1411+
'statusDetails' in error &&
1412+
error.statusDetails instanceof Array
1413+
) {
1414+
const protos = this._gaxModule.protobuf.Root.fromJSON(
1415+
jsonProtos,
1416+
) as unknown as gax.protobuf.Type;
1417+
error.statusDetails = decodeAnyProtosInArray(
1418+
error.statusDetails,
1419+
protos,
1420+
);
1421+
}
1422+
throw error;
1423+
});
13281424
}
13291425
/**
13301426
* Gets metadata on a pending or completed
@@ -1443,7 +1539,23 @@ export class DatabaseAdminClient {
14431539
this._log.info('getBackup response %j', response);
14441540
return [response, options, rawResponse];
14451541
},
1446-
);
1542+
)
1543+
.catch((error: any) => {
1544+
if (
1545+
error &&
1546+
'statusDetails' in error &&
1547+
error.statusDetails instanceof Array
1548+
) {
1549+
const protos = this._gaxModule.protobuf.Root.fromJSON(
1550+
jsonProtos,
1551+
) as unknown as gax.protobuf.Type;
1552+
error.statusDetails = decodeAnyProtosInArray(
1553+
error.statusDetails,
1554+
protos,
1555+
);
1556+
}
1557+
throw error;
1558+
});
14471559
}
14481560
/**
14491561
* Updates a pending or completed
@@ -1572,7 +1684,23 @@ export class DatabaseAdminClient {
15721684
this._log.info('updateBackup response %j', response);
15731685
return [response, options, rawResponse];
15741686
},
1575-
);
1687+
)
1688+
.catch((error: any) => {
1689+
if (
1690+
error &&
1691+
'statusDetails' in error &&
1692+
error.statusDetails instanceof Array
1693+
) {
1694+
const protos = this._gaxModule.protobuf.Root.fromJSON(
1695+
jsonProtos,
1696+
) as unknown as gax.protobuf.Type;
1697+
error.statusDetails = decodeAnyProtosInArray(
1698+
error.statusDetails,
1699+
protos,
1700+
);
1701+
}
1702+
throw error;
1703+
});
15761704
}
15771705
/**
15781706
* Deletes a pending or completed
@@ -1694,7 +1822,23 @@ export class DatabaseAdminClient {
16941822
this._log.info('deleteBackup response %j', response);
16951823
return [response, options, rawResponse];
16961824
},
1697-
);
1825+
)
1826+
.catch((error: any) => {
1827+
if (
1828+
error &&
1829+
'statusDetails' in error &&
1830+
error.statusDetails instanceof Array
1831+
) {
1832+
const protos = this._gaxModule.protobuf.Root.fromJSON(
1833+
jsonProtos,
1834+
) as unknown as gax.protobuf.Type;
1835+
error.statusDetails = decodeAnyProtosInArray(
1836+
error.statusDetails,
1837+
protos,
1838+
);
1839+
}
1840+
throw error;
1841+
});
16981842
}
16991843
/**
17001844
* Adds split points to specified tables, indexes of a database.
@@ -1829,7 +1973,23 @@ export class DatabaseAdminClient {
18291973
this._log.info('addSplitPoints response %j', response);
18301974
return [response, options, rawResponse];
18311975
},
1832-
);
1976+
)
1977+
.catch((error: any) => {
1978+
if (
1979+
error &&
1980+
'statusDetails' in error &&
1981+
error.statusDetails instanceof Array
1982+
) {
1983+
const protos = this._gaxModule.protobuf.Root.fromJSON(
1984+
jsonProtos,
1985+
) as unknown as gax.protobuf.Type;
1986+
error.statusDetails = decodeAnyProtosInArray(
1987+
error.statusDetails,
1988+
protos,
1989+
);
1990+
}
1991+
throw error;
1992+
});
18331993
}
18341994
/**
18351995
* Creates a new backup schedule.
@@ -1960,7 +2120,23 @@ export class DatabaseAdminClient {
19602120
this._log.info('createBackupSchedule response %j', response);
19612121
return [response, options, rawResponse];
19622122
},
1963-
);
2123+
)
2124+
.catch((error: any) => {
2125+
if (
2126+
error &&
2127+
'statusDetails' in error &&
2128+
error.statusDetails instanceof Array
2129+
) {
2130+
const protos = this._gaxModule.protobuf.Root.fromJSON(
2131+
jsonProtos,
2132+
) as unknown as gax.protobuf.Type;
2133+
error.statusDetails = decodeAnyProtosInArray(
2134+
error.statusDetails,
2135+
protos,
2136+
);
2137+
}
2138+
throw error;
2139+
});
19642140
}
19652141
/**
19662142
* Gets backup schedule for the input schedule name.
@@ -2087,7 +2263,23 @@ export class DatabaseAdminClient {
20872263
this._log.info('getBackupSchedule response %j', response);
20882264
return [response, options, rawResponse];
20892265
},
2090-
);
2266+
)
2267+
.catch((error: any) => {
2268+
if (
2269+
error &&
2270+
'statusDetails' in error &&
2271+
error.statusDetails instanceof Array
2272+
) {
2273+
const protos = this._gaxModule.protobuf.Root.fromJSON(
2274+
jsonProtos,
2275+
) as unknown as gax.protobuf.Type;
2276+
error.statusDetails = decodeAnyProtosInArray(
2277+
error.statusDetails,
2278+
protos,
2279+
);
2280+
}
2281+
throw error;
2282+
});
20912283
}
20922284
/**
20932285
* Updates a backup schedule.
@@ -2220,7 +2412,23 @@ export class DatabaseAdminClient {
22202412
this._log.info('updateBackupSchedule response %j', response);
22212413
return [response, options, rawResponse];
22222414
},
2223-
);
2415+
)
2416+
.catch((error: any) => {
2417+
if (
2418+
error &&
2419+
'statusDetails' in error &&
2420+
error.statusDetails instanceof Array
2421+
) {
2422+
const protos = this._gaxModule.protobuf.Root.fromJSON(
2423+
jsonProtos,
2424+
) as unknown as gax.protobuf.Type;
2425+
error.statusDetails = decodeAnyProtosInArray(
2426+
error.statusDetails,
2427+
protos,
2428+
);
2429+
}
2430+
throw error;
2431+
});
22242432
}
22252433
/**
22262434
* Deletes a backup schedule.
@@ -2347,7 +2555,23 @@ export class DatabaseAdminClient {
23472555
this._log.info('deleteBackupSchedule response %j', response);
23482556
return [response, options, rawResponse];
23492557
},
2350-
);
2558+
)
2559+
.catch((error: any) => {
2560+
if (
2561+
error &&
2562+
'statusDetails' in error &&
2563+
error.statusDetails instanceof Array
2564+
) {
2565+
const protos = this._gaxModule.protobuf.Root.fromJSON(
2566+
jsonProtos,
2567+
) as unknown as gax.protobuf.Type;
2568+
error.statusDetails = decodeAnyProtosInArray(
2569+
error.statusDetails,
2570+
protos,
2571+
);
2572+
}
2573+
throw error;
2574+
});
23512575
}
23522576

23532577
/**

0 commit comments

Comments
 (0)