Skip to content

Commit

Permalink
Use Axios's toJSON method to make shorter errors
Browse files Browse the repository at this point in the history
On an example erroring docassemble server (for example, this server returning
a [502 to a delete project](https://github.com/SuffolkLITLab/docassemble-EFSPIntegration/actions/runs/3641406524/jobs/6147303425)),
the entire axios error will print, which is that case in 1.8k lines, most of it
being garbage.

Axios has a `toJSON()` method on errors that should reduce length of the errors
being shown, as it will not print the most annoying parts of the long errors,
like the internal Axios socket objects

Still need to test, as it's difficult to get a server to 502 on
demand.

Fix #605.
  • Loading branch information
BryceStevenWilley committed Dec 12, 2022
1 parent 8c6a460 commit 21b02de
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/docassemble/docassemble_api_interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ da_i.throw_an_error_if_server_is_not_responding = async function ( options ) {
});
}

throw error;
throw error.toJSON();
}
}; // Ends da_i.throw_an_error_if_server_is_not_responding()

Expand Down Expand Up @@ -186,7 +186,7 @@ da_i.validate_api_key = async function ( api_key_options ) {
+ `organization's secrets.`
});
} // ends 403 message
throw error;
throw error.toJSON();
} // ends try to get dev_id
}; // Ends da_i.validate_api_key()

Expand Down Expand Up @@ -267,7 +267,7 @@ da_i.loop_to_create_project = async function( creation_options ) {
// A non-timeout, non-server error should just be thrown
} else {
log.error({ pre: `Ran into unexpected error when trying to create the Project.` });
throw error;
throw error.toJSON();

} // ends type of non-response error
} // ends type of response error
Expand Down Expand Up @@ -305,7 +305,7 @@ da_i.pull = async function ( pull_options ) {
// Pulling should not error
log.error({ pre: `Pulling into the docassemble Project ran into an unexpected error.` });
log.debug({ pre: `See https://docassemble.org/docs/api.html#playground_pull.` });
throw error;
throw error.toJSON();
}
}; // Ends da_i.pull()

Expand Down Expand Up @@ -435,15 +435,12 @@ da_i.delete_project = async function ( delete_options ) {
log.info({ pre: `Trying to delete Project ${ project_name }` });

try {

let response = await _da_REST.delete_project( timeout );
log.info({ pre: `Deleted Project "${ project_name }"` });

} catch ( error ) {
// Status 400
log.error({ pre: `Ran into an error when deleting Project "${ project_name }"` });
log.debug({ pre: `See https://docassemble.org/docs/api.html#playground_delete_project.` });
throw error;
throw error.toJSON();
}

}; // Ends da_i.delete_project()

0 comments on commit 21b02de

Please sign in to comment.