|
| 1 | +import { BoxSdkError } from '../box/errors.js'; |
| 2 | +import { SerializedData } from '../serialization/json.js'; |
| 3 | +import { sdIsEmpty } from '../serialization/json.js'; |
| 4 | +import { sdIsBoolean } from '../serialization/json.js'; |
| 5 | +import { sdIsNumber } from '../serialization/json.js'; |
| 6 | +import { sdIsString } from '../serialization/json.js'; |
| 7 | +import { sdIsList } from '../serialization/json.js'; |
| 8 | +import { sdIsMap } from '../serialization/json.js'; |
| 9 | +export interface MetadataError { |
| 10 | + /** |
| 11 | + * A Box-specific error code. */ |
| 12 | + readonly code?: string; |
| 13 | + /** |
| 14 | + * A short message describing the error. */ |
| 15 | + readonly message?: string; |
| 16 | + /** |
| 17 | + * A unique identifier for this response, which can be used |
| 18 | + * when contacting Box support. */ |
| 19 | + readonly requestId?: string; |
| 20 | + readonly rawData?: SerializedData; |
| 21 | +} |
| 22 | +export function serializeMetadataError(val: MetadataError): SerializedData { |
| 23 | + return { |
| 24 | + ['code']: val.code, |
| 25 | + ['message']: val.message, |
| 26 | + ['request_id']: val.requestId, |
| 27 | + }; |
| 28 | +} |
| 29 | +export function deserializeMetadataError(val: SerializedData): MetadataError { |
| 30 | + if (!sdIsMap(val)) { |
| 31 | + throw new BoxSdkError({ message: 'Expecting a map for "MetadataError"' }); |
| 32 | + } |
| 33 | + if (!(val.code == void 0) && !sdIsString(val.code)) { |
| 34 | + throw new BoxSdkError({ |
| 35 | + message: 'Expecting string for "code" of type "MetadataError"', |
| 36 | + }); |
| 37 | + } |
| 38 | + const code: undefined | string = val.code == void 0 ? void 0 : val.code; |
| 39 | + if (!(val.message == void 0) && !sdIsString(val.message)) { |
| 40 | + throw new BoxSdkError({ |
| 41 | + message: 'Expecting string for "message" of type "MetadataError"', |
| 42 | + }); |
| 43 | + } |
| 44 | + const message: undefined | string = |
| 45 | + val.message == void 0 ? void 0 : val.message; |
| 46 | + if (!(val.request_id == void 0) && !sdIsString(val.request_id)) { |
| 47 | + throw new BoxSdkError({ |
| 48 | + message: 'Expecting string for "request_id" of type "MetadataError"', |
| 49 | + }); |
| 50 | + } |
| 51 | + const requestId: undefined | string = |
| 52 | + val.request_id == void 0 ? void 0 : val.request_id; |
| 53 | + return { |
| 54 | + code: code, |
| 55 | + message: message, |
| 56 | + requestId: requestId, |
| 57 | + } satisfies MetadataError; |
| 58 | +} |
0 commit comments