Skip to content

Commit

Permalink
feat: expand some typings
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Dec 18, 2023
1 parent bd8ff73 commit bdea28f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
import { processAxiosError } from '../utils.js';

const createProcessAxiosRequestErrorInterceptor = (options) => {
Expand Down
15 changes: 15 additions & 0 deletions src/auth/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,21 @@ export async function hydrateAuthenticatedUser() {
* @typedef {import("axios").Axios} HttpClient
*/

/**
* @typedef {Object} CustomErrorAttributes
* @property {number} [httpErrorStatus]
* @property {'unknown-api-request-error'|'api-response-error'|'api-request-error'|'api-request-config-error'
* } [httpErrorType]
* @property {string} [httpErrorMessage]
* @property {string} [httpErrorRequestUrl]
* @property {string} [httpErrorRequestMethod]
* @property {any} [httpErrorResponseData]
*/

/**
* @typedef {import("axios").AxiosError & {customAttributes: CustomErrorAttributes}} DetailedAxiosError
*/

/**
* @typedef {Object} AuthService
* @property {typeof getAuthenticatedHttpClient} getAuthenticatedHttpClient
Expand Down
6 changes: 6 additions & 0 deletions src/auth/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ const logFrontendAuthError = (loggingService, error) => {
loggingService.logError(prefixedMessageError, prefixedMessageError.customAttributes);
};

/**
* Handle an Axios error
* @param {import("axios").AxiosError} axiosErrorObject The error
* @returns {import("./interface").DetailedAxiosError}
*/
const processAxiosError = (axiosErrorObject) => {
/** @type {import("./interface").DetailedAxiosError} */
const error = Object.create(axiosErrorObject);
const { request, response, config } = error;

Expand Down

0 comments on commit bdea28f

Please sign in to comment.