A simple answer is 301 pass link juice and 302 does not. There are documented cases where 302 is useful. https://digitalreadymarketing.com/advantage-302-redirect-example/ But generally speaking you should use 301 when redirecting a page / site.
301 is telling to search engine my page is no loger here, and has permanently moved to a new page. Please remove it from your index and pass credit to the new page. The HTTP response status code 302 Found is a common way of performing URL redirection. An HTTP response with this status code will additionally provide a URL in the location header field.
No one has completely explained the biggest usage. Lets say I have a site that has products and the url looks like this on our first platform (for whatever reason): "SITE.com/product/A2M3E5IS4PD" but then the site gets an upgrade after a couple months to be more seo friendly... or maybe we just switched platforms and the site changes to have that product on the new url: site.com/product/productname You'd 301 from the first link to the 2nd to tell search engines and browsers... HEY, this is the new place for this same page.
301 header error refers to permanent redirection of a page, for example If Page A has 301 redirection to Page B then all SEO matrices like Page Rank, Page Authority will transfer to Page B. 302 header error refers to temporarily redirection, it is used to redirect any website page to custom 404 page. Many eCommerce websites use 302 redirection for their products which has to remove temporarily.
Many webmasters don't understand the difference between a 301 and 302 redirect. Unlike users operating browsers, search engines sense the different types of redirects, and handle them differently. A 301 redirect means that the page has moved to a new location, permanently. A 302 redirect means that the move is temporary. Search engines need to figure out whether to keep the old page, or replace it with the one found at the new location. If the wrong type of redirect has been set up, search engines may become confused, resulting in a loss of traffic.........!!!!!!!!!