How to use axios-error - 9 common examples

To help you get started, we’ve selected a few axios-error examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Yoctol / messaging-apis / packages / messaging-api-viber / src / ViberClient.ts View on Github external
const response = await this._axios.post(
        path,

        // we can't apply a deep snake_case transform here
        // because it accept only PascalCase for keyboard and rich media
        snakecaseKeys(body, { deep: false })
      );

      const { config, request } = response;

      const data = (camelcaseKeysDeep(
        response.data
      ) as any) as Types.ResponseData;

      if (data.status !== 0) {
        throw new AxiosError(`Viber API - ${data.statusMessage}`, {
          config,
          request,
          response,
        });
      }

      return data;
    } catch (err) {
      throw new AxiosError(err.message, err);
    }
  }
github Yoctol / messaging-apis / packages / messaging-api-messenger / src / MessengerClient.ts View on Github external
function handleError(err: AxiosError): void {
  if (err.response && err.response.data) {
    const error = get(err, 'response.data.error', {});
    const msg = `Messenger API - ${error.code} ${error.type} ${error.message}`;
    throw new AxiosError(msg, err);
  }
  throw new AxiosError(err.message, err);
}
github Yoctol / messaging-apis / packages / messaging-api-viber / src / ViberClient.ts View on Github external
const data = (camelcaseKeysDeep(
        response.data
      ) as any) as Types.ResponseData;

      if (data.status !== 0) {
        throw new AxiosError(`Viber API - ${data.statusMessage}`, {
          config,
          request,
          response,
        });
      }

      return data;
    } catch (err) {
      throw new AxiosError(err.message, err);
    }
  }
github Yoctol / messaging-apis / packages / messaging-api-slack / src / SlackOAuthClient.ts View on Github external
response.data
      ) as any) as Types.OAuthAPIResponse;

      if (!data.ok) {
        const { config, request } = response;

        throw new AxiosError(`Slack API - ${data.error}`, {
          config,
          request,
          response,
        });
      }

      return data;
    } catch (err) {
      throw new AxiosError(err.message, err);
    }
  }
github Yoctol / messaging-apis / packages / messaging-api-line / src / LinePay.ts View on Github external
function throwWhenNotSuccess(res: {
  data: {
    returnCode: string;
    returnMessage: string;
    info?: any;
  };
}): any | never {
  if (res.data.returnCode !== '0000') {
    const { returnCode, returnMessage } = res.data;
    const msg = `LINE PAY API - ${returnCode} ${returnMessage}`;
    throw new AxiosError(msg);
  }
  return res.data.info;
}
github bottenderjs / bottender-facebook / src / FacebookClient.js View on Github external
function handleError(err) {
  const { error } = err.response.data;
  const msg = `Messenger API - ${error.code} ${error.type} ${error.message}`;
  throw new AxiosError(msg, err);
}
github Yoctol / messaging-apis / packages / messaging-api-messenger / src / MessengerClient.ts View on Github external
function handleError(err: AxiosError): void {
  if (err.response && err.response.data) {
    const error = get(err, 'response.data.error', {});
    const msg = `Messenger API - ${error.code} ${error.type} ${error.message}`;
    throw new AxiosError(msg, err);
  }
  throw new AxiosError(err.message, err);
}
github Yoctol / messaging-apis / packages / messaging-api-line / src / LineClient.ts View on Github external
message: string;
      }[];
    };
  };
}): never {
  if (err.response && err.response.data) {
    const { message, details } = err.response.data;
    let msg = `LINE API - ${message}`;
    if (details && details.length > 0) {
      details.forEach(detail => {
        msg += `\n- ${detail.property}: ${detail.message}`;
      });
    }
    throw new AxiosError(msg, err);
  }
  throw new AxiosError(err.message, err);
}
github Yoctol / messaging-apis / packages / messaging-api-telegram / src / TelegramClient.ts View on Github external
response,
        });
      }

      if (isPlainObject(data.result) || Array.isArray(data.result)) {
        return camelcaseKeysDeep(data.result);
      }
      return data.result;
    } catch (err) {
      if (err.response && err.response.data) {
        const { error_code, description } = err.response.data;
        const msg = `Telegram API - ${error_code} ${description || ''}`;

        throw new AxiosError(msg, err);
      }
      throw new AxiosError(err.message, err);
    }
  }

axios-error

Axios error wrapper that aim to provide clear error message to developers

MIT
Latest version published 4 years ago

Package Health Score

56 / 100
Full package analysis

Popular axios-error functions