Tuesday, February 20, 2018

Amazon Web Services get Search() response needs try catch continuously - development

Amazon Web Services get Search() response needs try catch continuously

I´m using Amazon Web Services in Laravel app. I created this page:
https://frikinow.com/libros-frikis

If you reload the page sometimes works and sometimes does not.

this is because the amazon method needs to be continuously put into a try catch

public function getLibrosFrikis() {

        # string $category, string $keyword = null, int $page = 1
        try {
            $page1  = AmazonProduct::search('Books', 'libros,frikis' , 1);

            $page2  = AmazonProduct::search('Books', 'libros,frikis' , 2);

            $page3  = AmazonProduct::search('Books', 'libros,frikis' , 3);


            $articles = collect([$page1['Items']['Item'],$page2['Items']['Item'],$page3['Items']['Item']])->flatten(1);


            $params = array(

                'articles' => $articles,
            );

        } 
        catch(ServerException $e) {
        }


        return view('pages.ecommerce.libros_frikis', $params);
      }

I managed to put it in the WebController but I don’t know how to capture the exception in Blade view HTML:

<div class="row-flex-shrink row-flex-wrap">

        @foreach($articles as $article)



            <div class="col-sm-4 col-md-3" style="margin-bottom: 16px;">
                <a href="" target="_blank" rel="nofollow">
                    <div class="item amazon-item">
                        <img src="" alt="" class="img-responsive">
                        <div class="title"></div>
                        <div class="btn btn-warning">ver precio</div>
                    </div>
                </a>
            </div>


        @endforeach

    </div>

How can I control this?



from Laravel Questions and Answers https://laravelquestions.com/php/amazon-web-services-get-search-response-needs-try-catch-continuously/
via Lzo Media

No comments:

Post a Comment