{"size": 640, "ext": "js", "max_stars_repo_path": "plugins/axios.js", "max_stars_repo_name": "MichaelGrove/memo-nuxt", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "plugins/axios.js", "max_issues_repo_name": "MichaelGrove/memo-nuxt", "max_issues_repo_issues_event_min_datetime": "2020-07-26T15:25:07.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-02T16:32:44.000Z", "max_forks_repo_path": "plugins/axios.js", "max_forks_repo_name": "MichaelGrove/memo-nuxt", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 6, "max_forks_count": null, "avg_line_length": 22.0689655172, "max_line_length": 49, "alphanum_fraction": 0.6140625}
const getUser = () => {
	try {
		return JSON.parse(localStorage.getItem('user'))
	} catch (e) {
		return null
	}
}

export default function ({ $axios, redirect }) {
	const user = getUser()
	if (user && user.token) {
		$axios.setToken(user.token, 'Bearer')
	}

	$axios.onError((error) => {
		if (error.response.status === 500) {
			redirect('/')
		} else if (error.response.status === 403) {
			$axios.setToken(null)
			localStorage.removeItem('user')
		} else if (error.response.status === 422) {
			const { errors } = error.response.data
			if (errors && errors.length > 0) {
				window.alert(JSON.stringify(errors[0].msg))
			}
		}
	})
}
