diff --git a/src/main/render/thrift-server/exception/index.ts b/src/main/render/thrift-server/exception/index.ts index 5275a492..8570000a 100644 --- a/src/main/render/thrift-server/exception/index.ts +++ b/src/main/render/thrift-server/exception/index.ts @@ -10,5 +10,5 @@ export function renderException( node: ExceptionDefinition, state: IRenderState, ): Array { - return renderStruct(node, state) + return renderStruct(node, state, true) } diff --git a/src/main/render/thrift-server/identifiers.ts b/src/main/render/thrift-server/identifiers.ts index 8c6d1847..2b3b54cd 100644 --- a/src/main/render/thrift-server/identifiers.ts +++ b/src/main/render/thrift-server/identifiers.ts @@ -33,6 +33,7 @@ export const THRIFT_IDENTIFIERS = { 'thrift.InputBufferUnderrunError', ), StructLike: ts.createIdentifier('thrift.StructLike'), + ErrorStructLike: ts.createIdentifier('thrift.ErrorStructLike'), } export const THRIFT_TYPES = { diff --git a/src/main/render/thrift-server/struct/class.ts b/src/main/render/thrift-server/struct/class.ts index b96e4796..fe08421b 100644 --- a/src/main/render/thrift-server/struct/class.ts +++ b/src/main/render/thrift-server/struct/class.ts @@ -27,6 +27,7 @@ import { classNameForStruct, createSuperCall, extendsAbstract, + extendsAbstractError, implementsInterface, looseNameForStruct, throwForField, @@ -38,6 +39,7 @@ export function renderClass( node: InterfaceWithFields, state: IRenderState, isExported: boolean, + extendError: boolean = false, ): ts.ClassDeclaration { const fields: Array = [ ...createFieldsForStruct(node, state), @@ -97,7 +99,10 @@ export function renderClass( tokens(isExported), classNameForStruct(node, state).replace('__NAMESPACE__', ''), [], - [extendsAbstract(), implementsInterface(node, state)], // heritage + [ + extendError ? extendsAbstractError() : extendsAbstract(), + implementsInterface(node, state), + ], // heritage [ ...fields, ctor, diff --git a/src/main/render/thrift-server/struct/index.ts b/src/main/render/thrift-server/struct/index.ts index 8ce46603..81c992b8 100644 --- a/src/main/render/thrift-server/struct/index.ts +++ b/src/main/render/thrift-server/struct/index.ts @@ -13,10 +13,11 @@ import { renderClass } from './class' export function renderStruct( node: InterfaceWithFields, state: IRenderState, + extendError: boolean = false, ): Array { return [ ...renderInterface(node, state, true), renderToolkit(node, state, true), - renderClass(node, state, true), + renderClass(node, state, true, extendError), ] } diff --git a/src/main/render/thrift-server/struct/utils.ts b/src/main/render/thrift-server/struct/utils.ts index 4955cc1d..a0594e8b 100644 --- a/src/main/render/thrift-server/struct/utils.ts +++ b/src/main/render/thrift-server/struct/utils.ts @@ -133,6 +133,15 @@ export function extendsAbstract(): ts.HeritageClause { ]) } +export function extendsAbstractError(): ts.HeritageClause { + return ts.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [ + ts.createExpressionWithTypeArguments( + [], + THRIFT_IDENTIFIERS.ErrorStructLike, + ), + ]) +} + export function implementsInterface( node: InterfaceWithFields, state: IRenderState,