MCPcopy Create free account
hub / github.com/hey-api/hey-api / except

Method except

packages/openapi-python/src/py-dsl/stmt/try.ts:103–137  ·  view source on GitHub ↗

* Add (or merge into) an except clause. * * ```ts * $.try(...) * .except('ValueError', 'e', body1, body2) // except ValueError as e: * .except(['TypeError', 'KeyError'], 'e', ...) // except (TypeError, KeyError) as e: * .except('ValueError', moreBody) // merg

(
    types: MaybeArray<ExceptType>,
    nameOrBody?: NodeName | DoExpr,
    ...body: Array<DoExpr>
  )

Source from the content-addressed store, hash-verified

101 * @param body Remaining body statements.
102 */
103 except(
104 types: MaybeArray<ExceptType>,
105 nameOrBody?: NodeName | DoExpr,
106 ...body: Array<DoExpr>
107 ): this {
108 const typeArr = Array.isArray(types) ? types : [types];
109 const key = exceptKey(typeArr);
110
111 let name: Ref<NodeName> | undefined;
112 let bodyItems: Array<DoExpr>;
113
114 // Disambiguate: if the second arg is a plain string that looks like
115 // an identifier (no dots, no spaces, not a DSL node) treat it as
116 // the `as` name. Otherwise it's the first body expression.
117 if (nameOrBody !== undefined && this._isNodeName(nameOrBody)) {
118 name = ref(nameOrBody as NodeName);
119 bodyItems = body;
120 } else if (nameOrBody !== undefined) {
121 bodyItems = [nameOrBody as DoExpr, ...body];
122 } else {
123 bodyItems = body;
124 }
125
126 const existing = this._exceptIndex.get(key);
127 if (existing !== undefined) {
128 const entry = this._excepts[existing]!;
129 entry.body.push(...bodyItems);
130 if (name !== undefined) entry.name = name;
131 } else {
132 this._exceptIndex.set(key, this._excepts.length);
133 this._excepts.push({ body: bodyItems, name, types: typeArr });
134 }
135
136 return this;
137 }
138
139 /** Add a bare `except:` clause (catches everything). */
140 exceptAll(...body: Array<DoExpr>): this {

Callers

nothing calls this directly

Calls 6

_isNodeNameMethod · 0.95
refFunction · 0.90
exceptKeyFunction · 0.85
pushMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected