Skip to content

Commit c2faf8c

Browse files
committed
refactor
1 parent a51097e commit c2faf8c

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

packages/itwin/measure-tools/src/api/FormatterUtils.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IModelApp, QuantityType } from "@itwin/core-frontend";
99
import { FormatTraits } from "@itwin/core-quantity";
1010
import { MeasureTools } from "../MeasureTools.js";
1111

12-
import type { FormatProps , FormatterSpec} from "@itwin/core-quantity";
12+
import type { FormatDefinition, FormatProps , FormatterSpec} from "@itwin/core-quantity";
1313
export namespace FormatterUtils {
1414

1515
/**
@@ -226,17 +226,13 @@ export namespace FormatterUtils {
226226
* @returns A FormatterSpec for bearing formatting.
227227
*/
228228
export async function getBearingFormatterSpec(bearingKoQ: string, persistenceUnitName: string): Promise<FormatterSpec | undefined> {
229-
let formatProps: FormatProps | undefined;
230-
229+
let formatProps: FormatDefinition;
231230
try {
232-
// First try to get format props from the formats provider using the bearingKoQ
233-
formatProps = await IModelApp.formatsProvider.getFormat(bearingKoQ);
231+
// Get format props from the formats provider using the bearingKoQ. If undefined, use default bearing format
232+
const result = await IModelApp.formatsProvider.getFormat(bearingKoQ);
233+
formatProps = result ?? getDefaultBearingFormatProps();
234234
} catch {
235-
// If that fails, formatProps will remain undefined and we'll use the fallback
236-
}
237-
238-
// If we couldn't get format props from the provider, use the default bearing format
239-
if (!formatProps) {
235+
// If an error occurs, use the default bearing format
240236
formatProps = getDefaultBearingFormatProps();
241237
}
242238

0 commit comments

Comments
 (0)