@atproto/xrpc
Advanced tools
Comparing version 0.0.1 to 0.0.2
import { z } from 'zod'; | ||
import { ValidationError } from '@atproto/lexicon'; | ||
export declare type QueryParams = Record<string, any>; | ||
@@ -83,1 +84,7 @@ export declare type Headers = Record<string, string>; | ||
} | ||
export declare class XRPCInvalidResponseError extends XRPCError { | ||
lexiconNsid: string; | ||
validationError: ValidationError; | ||
responseBody: unknown; | ||
constructor(lexiconNsid: string, validationError: ValidationError, responseBody: unknown); | ||
} |
{ | ||
"name": "@atproto/xrpc", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"main": "src/index.ts", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -1,2 +0,2 @@ | ||
import { Lexicons } from '@atproto/lexicon' | ||
import { Lexicons, ValidationError } from '@atproto/lexicon' | ||
import { | ||
@@ -21,2 +21,3 @@ getMethodSchemaHTTPMethod, | ||
XRPCError, | ||
XRPCInvalidResponseError, | ||
} from './types' | ||
@@ -113,2 +114,11 @@ | ||
if (resCode === ResponseType.Success) { | ||
try { | ||
this.baseClient.lex.assertValidXrpcOutput(methodNsid, res.body) | ||
} catch (e: any) { | ||
if (e instanceof ValidationError) { | ||
throw new XRPCInvalidResponseError(methodNsid, e, res.body) | ||
} else { | ||
throw e | ||
} | ||
} | ||
return new XRPCResponse(res.body, res.headers) | ||
@@ -115,0 +125,0 @@ } else { |
import { z } from 'zod' | ||
import { ValidationError } from '@atproto/lexicon' | ||
@@ -99,1 +100,15 @@ export type QueryParams = Record<string, any> | ||
} | ||
export class XRPCInvalidResponseError extends XRPCError { | ||
constructor( | ||
public lexiconNsid: string, | ||
public validationError: ValidationError, | ||
public responseBody: unknown, | ||
) { | ||
super( | ||
ResponseType.InvalidResponse, | ||
ResponseTypeStrings[ResponseType.InvalidResponse], | ||
`The server gave an invalid response and may be out of date.`, | ||
) | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
416547
4683