Skip to content

Commit

Permalink
refactor: on parsing Lambda result
Browse files Browse the repository at this point in the history
  • Loading branch information
horiuchi committed Nov 13, 2023
1 parent 89838f3 commit dbc1872
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,25 +507,20 @@ function buildDataSource(
`Request failed with status code ${result.StatusCode ?? ''}`,
);
}
const s = result.Payload?.toLocaleString();
const res = s == null || s.length === 0 ? null : JSON.parse(s);
if (result.FunctionError) {
const s = result.Payload?.toLocaleString();
if (s != null) {
const data = JSON.parse(s);
if (res != null) {
throw {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
type: `Lambda:${data.errorType}`,
message: data.errorMessage,
type: `Lambda:${res.errorType}`,
message: res.errorMessage,
};
} else {
throw new Error(result.FunctionError);
}
}
const s = result.Payload?.toLocaleString();
if (s == null) {
return null;
} else {
return JSON.parse(s);
}
return res;
},
};
}
Expand Down

0 comments on commit dbc1872

Please sign in to comment.