UNPKG

roiact

Version:
26 lines (22 loc) 779 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toastOnError = toastOnError; var _reactToastify = require("react-toastify"); var _Request = require("../Utils/Request"); // just a decorator which calls given function if response is ok, // otherwise shows a toast with error information function toastOnError(fn, errorMessage) { var onError = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {}; return function (response) { if (response.ok) { fn(response); } else { (0, _reactToastify.toast)(errorMessage.replace('{error}', (0, _Request.getResponseStringError)(response)), { type: 'error' }); onError((0, _Request.getResponseStringError)(response)); } }; }