Skip to content

Commit

Permalink
executor: prevent a nasty error message if an HTTP error bubbles up
Browse files Browse the repository at this point in the history
  • Loading branch information
gcampax committed Jan 7, 2022
1 parent 48a28d8 commit d0097fd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/dialogue-agent/statement_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const MORE_SIZE = 50;
const PAGE_SIZE = 10;

interface ErrorWithCode extends Error {
code ?: string;
code ?: unknown;
}

/**
Expand Down Expand Up @@ -172,7 +172,9 @@ export default class InferenceStatementExecutor {
const annotations : Ast.AnnotationMap = {};
let errorValue;
if (error) {
if (error.code)
if (typeof error.code === 'number')
errorValue = new Ast.Value.Enum(`http_${error.code}`);
else if (typeof error.code === 'string' && error.code)
errorValue = new Ast.Value.Enum(error.code);
else
errorValue = new Ast.Value.String(error.message);
Expand Down

0 comments on commit d0097fd

Please sign in to comment.