Files
plexjs/src/sdk/models/errors/getsessions.ts

342 lines
10 KiB
TypeScript

/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod";
import { remap as remap$ } from "../../../lib/primitives.js";
import { safeParse } from "../../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { PlexAPIError } from "./plexapierror.js";
import { SDKValidationError } from "./sdkvalidationerror.js";
export type GetSessionsSessionsErrors = {
code?: number | undefined;
message?: string | undefined;
status?: number | undefined;
};
/**
* Unauthorized - Returned if the X-Plex-Token is missing from the header or query.
*/
export type GetSessionsUnauthorizedData = {
errors?: Array<GetSessionsSessionsErrors> | undefined;
/**
* Raw HTTP response; suitable for custom response parsing
*/
rawResponse?: Response | undefined;
};
/**
* Unauthorized - Returned if the X-Plex-Token is missing from the header or query.
*/
export class GetSessionsUnauthorized extends PlexAPIError {
errors?: Array<GetSessionsSessionsErrors> | undefined;
/** The original data that was passed to this error instance. */
data$: GetSessionsUnauthorizedData;
constructor(
err: GetSessionsUnauthorizedData,
httpMeta: { response: Response; request: Request; body: string },
) {
const message = "message" in err && typeof err.message === "string"
? err.message
: `API error occurred: ${JSON.stringify(err)}`;
super(message, httpMeta);
this.data$ = err;
if (err.errors != null) this.errors = err.errors;
this.name = "GetSessionsUnauthorized";
}
}
export type GetSessionsErrors = {
code?: number | undefined;
message?: string | undefined;
status?: number | undefined;
};
/**
* Bad Request - A parameter was not specified, or was specified incorrectly.
*/
export type GetSessionsBadRequestData = {
errors?: Array<GetSessionsErrors> | undefined;
/**
* Raw HTTP response; suitable for custom response parsing
*/
rawResponse?: Response | undefined;
};
/**
* Bad Request - A parameter was not specified, or was specified incorrectly.
*/
export class GetSessionsBadRequest extends PlexAPIError {
errors?: Array<GetSessionsErrors> | undefined;
/** The original data that was passed to this error instance. */
data$: GetSessionsBadRequestData;
constructor(
err: GetSessionsBadRequestData,
httpMeta: { response: Response; request: Request; body: string },
) {
const message = "message" in err && typeof err.message === "string"
? err.message
: `API error occurred: ${JSON.stringify(err)}`;
super(message, httpMeta);
this.data$ = err;
if (err.errors != null) this.errors = err.errors;
this.name = "GetSessionsBadRequest";
}
}
/** @internal */
export const GetSessionsSessionsErrors$inboundSchema: z.ZodType<
GetSessionsSessionsErrors,
z.ZodTypeDef,
unknown
> = z.object({
code: z.number().int().optional(),
message: z.string().optional(),
status: z.number().int().optional(),
});
/** @internal */
export type GetSessionsSessionsErrors$Outbound = {
code?: number | undefined;
message?: string | undefined;
status?: number | undefined;
};
/** @internal */
export const GetSessionsSessionsErrors$outboundSchema: z.ZodType<
GetSessionsSessionsErrors$Outbound,
z.ZodTypeDef,
GetSessionsSessionsErrors
> = z.object({
code: z.number().int().optional(),
message: z.string().optional(),
status: z.number().int().optional(),
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace GetSessionsSessionsErrors$ {
/** @deprecated use `GetSessionsSessionsErrors$inboundSchema` instead. */
export const inboundSchema = GetSessionsSessionsErrors$inboundSchema;
/** @deprecated use `GetSessionsSessionsErrors$outboundSchema` instead. */
export const outboundSchema = GetSessionsSessionsErrors$outboundSchema;
/** @deprecated use `GetSessionsSessionsErrors$Outbound` instead. */
export type Outbound = GetSessionsSessionsErrors$Outbound;
}
export function getSessionsSessionsErrorsToJSON(
getSessionsSessionsErrors: GetSessionsSessionsErrors,
): string {
return JSON.stringify(
GetSessionsSessionsErrors$outboundSchema.parse(getSessionsSessionsErrors),
);
}
export function getSessionsSessionsErrorsFromJSON(
jsonString: string,
): SafeParseResult<GetSessionsSessionsErrors, SDKValidationError> {
return safeParse(
jsonString,
(x) => GetSessionsSessionsErrors$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'GetSessionsSessionsErrors' from JSON`,
);
}
/** @internal */
export const GetSessionsUnauthorized$inboundSchema: z.ZodType<
GetSessionsUnauthorized,
z.ZodTypeDef,
unknown
> = z.object({
errors: z.array(z.lazy(() => GetSessionsSessionsErrors$inboundSchema))
.optional(),
RawResponse: z.instanceof(Response).optional(),
request$: z.instanceof(Request),
response$: z.instanceof(Response),
body$: z.string(),
})
.transform((v) => {
const remapped = remap$(v, {
"RawResponse": "rawResponse",
});
return new GetSessionsUnauthorized(remapped, {
request: v.request$,
response: v.response$,
body: v.body$,
});
});
/** @internal */
export type GetSessionsUnauthorized$Outbound = {
errors?: Array<GetSessionsSessionsErrors$Outbound> | undefined;
RawResponse?: never | undefined;
};
/** @internal */
export const GetSessionsUnauthorized$outboundSchema: z.ZodType<
GetSessionsUnauthorized$Outbound,
z.ZodTypeDef,
GetSessionsUnauthorized
> = z.instanceof(GetSessionsUnauthorized)
.transform(v => v.data$)
.pipe(
z.object({
errors: z.array(z.lazy(() => GetSessionsSessionsErrors$outboundSchema))
.optional(),
rawResponse: z.instanceof(Response).transform(() => {
throw new Error("Response cannot be serialized");
}).optional(),
}).transform((v) => {
return remap$(v, {
rawResponse: "RawResponse",
});
}),
);
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace GetSessionsUnauthorized$ {
/** @deprecated use `GetSessionsUnauthorized$inboundSchema` instead. */
export const inboundSchema = GetSessionsUnauthorized$inboundSchema;
/** @deprecated use `GetSessionsUnauthorized$outboundSchema` instead. */
export const outboundSchema = GetSessionsUnauthorized$outboundSchema;
/** @deprecated use `GetSessionsUnauthorized$Outbound` instead. */
export type Outbound = GetSessionsUnauthorized$Outbound;
}
/** @internal */
export const GetSessionsErrors$inboundSchema: z.ZodType<
GetSessionsErrors,
z.ZodTypeDef,
unknown
> = z.object({
code: z.number().int().optional(),
message: z.string().optional(),
status: z.number().int().optional(),
});
/** @internal */
export type GetSessionsErrors$Outbound = {
code?: number | undefined;
message?: string | undefined;
status?: number | undefined;
};
/** @internal */
export const GetSessionsErrors$outboundSchema: z.ZodType<
GetSessionsErrors$Outbound,
z.ZodTypeDef,
GetSessionsErrors
> = z.object({
code: z.number().int().optional(),
message: z.string().optional(),
status: z.number().int().optional(),
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace GetSessionsErrors$ {
/** @deprecated use `GetSessionsErrors$inboundSchema` instead. */
export const inboundSchema = GetSessionsErrors$inboundSchema;
/** @deprecated use `GetSessionsErrors$outboundSchema` instead. */
export const outboundSchema = GetSessionsErrors$outboundSchema;
/** @deprecated use `GetSessionsErrors$Outbound` instead. */
export type Outbound = GetSessionsErrors$Outbound;
}
export function getSessionsErrorsToJSON(
getSessionsErrors: GetSessionsErrors,
): string {
return JSON.stringify(
GetSessionsErrors$outboundSchema.parse(getSessionsErrors),
);
}
export function getSessionsErrorsFromJSON(
jsonString: string,
): SafeParseResult<GetSessionsErrors, SDKValidationError> {
return safeParse(
jsonString,
(x) => GetSessionsErrors$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'GetSessionsErrors' from JSON`,
);
}
/** @internal */
export const GetSessionsBadRequest$inboundSchema: z.ZodType<
GetSessionsBadRequest,
z.ZodTypeDef,
unknown
> = z.object({
errors: z.array(z.lazy(() => GetSessionsErrors$inboundSchema)).optional(),
RawResponse: z.instanceof(Response).optional(),
request$: z.instanceof(Request),
response$: z.instanceof(Response),
body$: z.string(),
})
.transform((v) => {
const remapped = remap$(v, {
"RawResponse": "rawResponse",
});
return new GetSessionsBadRequest(remapped, {
request: v.request$,
response: v.response$,
body: v.body$,
});
});
/** @internal */
export type GetSessionsBadRequest$Outbound = {
errors?: Array<GetSessionsErrors$Outbound> | undefined;
RawResponse?: never | undefined;
};
/** @internal */
export const GetSessionsBadRequest$outboundSchema: z.ZodType<
GetSessionsBadRequest$Outbound,
z.ZodTypeDef,
GetSessionsBadRequest
> = z.instanceof(GetSessionsBadRequest)
.transform(v => v.data$)
.pipe(
z.object({
errors: z.array(z.lazy(() => GetSessionsErrors$outboundSchema))
.optional(),
rawResponse: z.instanceof(Response).transform(() => {
throw new Error("Response cannot be serialized");
}).optional(),
}).transform((v) => {
return remap$(v, {
rawResponse: "RawResponse",
});
}),
);
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace GetSessionsBadRequest$ {
/** @deprecated use `GetSessionsBadRequest$inboundSchema` instead. */
export const inboundSchema = GetSessionsBadRequest$inboundSchema;
/** @deprecated use `GetSessionsBadRequest$outboundSchema` instead. */
export const outboundSchema = GetSessionsBadRequest$outboundSchema;
/** @deprecated use `GetSessionsBadRequest$Outbound` instead. */
export type Outbound = GetSessionsBadRequest$Outbound;
}