Skip to content

Commit

Permalink
fix: add more descriptive errors on task/workflow run failure
Browse files Browse the repository at this point in the history
Signed-off-by: eugenejahn <[email protected]>
  • Loading branch information
eugenejahn committed Apr 11, 2022
1 parent 4721e84 commit 8bb5ddc
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/models/AdminEntity/transformRequestError.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
import { AxiosError } from 'axios';
import { NotAuthorizedError, NotFoundError } from 'errors/fetchErrors';
import { Admin } from 'flyteidl';
import { decodeProtoResponse } from './utils';

// to enrich the error message by adding the response
function decodeErrorResponseMessage(error: AxiosError) {
try {
// probablly using a wrong decode type.. is there a decode type for the error message?
const decodedErrorResponseMessage = decodeProtoResponse(
error.response?.data,
Admin.RawOutputDataConfig,
);
if (decodedErrorResponseMessage && decodedErrorResponseMessage.outputLocationPrefix) {
const errorStatusMessage = error?.message;
const errorResponseMessage = decodedErrorResponseMessage.outputLocationPrefix;

return new Error(`${errorStatusMessage} ${errorResponseMessage}`);
}
} catch (err) {
// do nothing
}
return error;
}

/** Detects special cases for errors returned from Axios and lets others pass through. */
export function transformRequestError(err: unknown, path: string) {
const error = err as AxiosError;

if (!error.response) {
return error;
}
Expand All @@ -17,5 +40,5 @@ export function transformRequestError(err: unknown, path: string) {
return new NotAuthorizedError();
}

return error;
return decodeErrorResponseMessage(error);
}

0 comments on commit 8bb5ddc

Please sign in to comment.