<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Riccardo Scasseddu on Medium]]></title>
        <description><![CDATA[Stories by Riccardo Scasseddu on Medium]]></description>
        <link>https://medium.com/@enne?source=rss-2d18889a8df7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aw4PSRa1gQpruPTAmx9Crg.jpeg</url>
            <title>Stories by Riccardo Scasseddu on Medium</title>
            <link>https://medium.com/@enne?source=rss-2d18889a8df7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 12:49:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@enne/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Exception handling for json endpoints in a Laravel 5 application]]></title>
            <link>https://medium.com/@enne/exception-handling-for-json-endpoints-in-a-laravel-5-application-95971c548f15?source=rss-2d18889a8df7------2</link>
            <guid isPermaLink="false">https://medium.com/p/95971c548f15</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Riccardo Scasseddu]]></dc:creator>
            <pubDate>Mon, 27 Feb 2017 14:21:28 GMT</pubDate>
            <atom:updated>2017-02-27T21:48:41.577Z</atom:updated>
            <content:encoded><![CDATA[<p>I have been looking for a way to slim up my controllers and give to end-user significative error messages able to abstract system exceptions and possibly a way to speed up the writing of integration tests.</p><p>As most of us, in my application I have one exception per “problem”. Some examples could be:<br>- PaymentFailedException<br>- PermissionException<br>…and so on</p><p>Given an example exception, the base response structure I was looking for is:</p><pre>{<br>    “status”: “The user caused an example exception”,<br>    “code”: “exception.example-exception”,<br>    “messages”: [ <br>        &quot;This is an additional message&quot;,<br>        &quot;This is an additional message #2&quot;<br>    ]<br>}</pre><p>And maybe a result like this for a “ModelNotFoundException” if throwed in the <strong>Album</strong>Controller:</p><pre>{<br>    “status”: “The picture was not found in specified album”,<br>    “code”: “<strong>album</strong>.picture-not-found”,<br>    “messages”: [<br>    ]<br>}</pre><p>and in the end this response for a “ValidationException” if throwed in the <strong>Film</strong>Controller:</p><pre>{<br>    “status&quot;: “Missing film details”,<br>    “code&quot;: “<strong>film</strong>.validation-exception”,<br>    “messages&quot;: [<br>        “The title field is required.”,<br>        “The description field is required.”<br>    ]<br>}</pre><p>It should be clear that the fields i want to expose to the api are:<br>- <strong>status</strong> clear readable explanation of what is wrong (ideally ready to be passed to an error dialog for example)<br>- <strong>code</strong> an identifier for the error, in the form of “thrower.exception”<br>- <strong>messages</strong> additional array of text</p><p>This is what i came up to:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/acee3aaa4edce67b76098db564122ae4/href">https://medium.com/media/acee3aaa4edce67b76098db564122ae4/href</a></iframe><p>To give it a try, just copy the previous class and replace the render method in Handler.php</p><pre><strong>public function </strong>render($request, Exception $exception)<br>{<br>    <strong>if </strong>($request-&gt;wantsJson()) {<br>        <strong>return </strong>ExceptionResponseFactory::<em>generate</em>($exception);<br>    }<br>    <strong>return parent</strong>::<em>render</em>($request, $exception);<br>}</pre><p>It’s now clear that if an exception is not explicitly handled the json response is:</p><pre>{<br>    “status”: “Translation of the code”,<br>    “code”: “controller-or-exception.dashed-case-name-of-exception”,<br>    “messages”: [ <br>        &quot;exception message if present&quot;<br>    ]<br>}</pre><p>Keep in mind that Laravel throws an “ModelNotFoundException” when:<br>- <a href="https://laravel.com/docs/5.4/eloquent#retrieving-single-models">A model if not found when called “findOrFail”</a><br>- <a href="https://laravel.com/docs/5.4/routing#implicit-binding">A model is not found when specified in path binding</a></p><p>This code is just and example, adapted to be (hopefully) more readable, feel free to do use it at your pleasure.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95971c548f15" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use minio as docker registry storage driver]]></title>
            <link>https://medium.com/@enne/use-minio-as-docker-registry-storage-driver-c9c72c72cc87?source=rss-2d18889a8df7------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9c72c72cc87</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[minio]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[amazon-s3]]></category>
            <dc:creator><![CDATA[Riccardo Scasseddu]]></dc:creator>
            <pubDate>Wed, 15 Feb 2017 18:29:38 GMT</pubDate>
            <atom:updated>2017-02-16T20:04:42.158Z</atom:updated>
            <content:encoded><![CDATA[<p>Among all the various ways of saving files, Amazon s3 service has defined a standard, a lot of services and software supports natively using it as “Object block storage” (that is just a fancy alternative for “saves files and stuff”) and nowadays there are a lot of s3 drop-in replacements.</p><p>My favourite one in <a href="https://minio.io/">minio</a>, written in go and ridiculously easy to set up, for the installation you should look at the <a href="http://docs.minio.io/">official documentation</a>.</p><p>Today i will show you a little thing i have put up with minio, using it as a remote storage for my private docker registry</p><h4>Variables</h4><p>Keep in mind you will need a working minio installation with an dedicated bucket, and the following variables:</p><pre>NAME                   EXAMPLE<br>{MINIO_ACCESS_KEY}  =&gt; PWMJHQ01EXRWYRVM3UJB<br>{MINIO_SECRET_KEY}  =&gt; N2nEexm6bSEITcvrA97Mu/uR/yvWpy1bXoGGetYE<br>{REGION}            =&gt; us-east-1<br>{REGION_ENDPOINT}   =&gt; <a href="https://storage.ennetech.me:9000/">https://minio.example.com:9000/</a><br>{BUCKET_NAME}       =&gt; <a href="https://storage.ennetech.me:9000/">d</a>ocker-registry</pre><h4>Configuration</h4><p>We have to write two configuration files, one for the registry configuration (config.yml) and one to build a docker image that uses it (Dockerfile)</p><p><strong>config.yml</strong></p><pre>version: 0.1<br>log:<br>    fields:<br>        service: registry<br>http:<br>    addr: :5000<br>storage:<br>    cache:<br>        layerinfo: inmemory<br>    s3:<br>        accesskey: {MINIO_ACCESS_KEY}<br>        secretkey: {MINIO_SECRET_KEY}<br>        region: {REGION}<br>        regionendpoint: {REGION_ENDPOINT}<br>        bucket: {BUCKET_NAME}<br>        encrypt: false<br>        secure: true<br>        v4auth: true<br>        chunksize: 5242880<br>        rootdirectory: /</pre><p><strong>Dockerfile</strong></p><pre>FROM registry:2<br>COPY config.yml /etc/docker/registry/config.yml</pre><p>Note: Be sure to run the lastest version of minio, versions before “RELEASE.2017–02–16T01–47–30Z” are incompatible with versions of docker registy greater than 2.5.1</p><h4>Build and run</h4><p>Now assuming that the <em>Dockerfile </em>and the <em>config.yml</em> are in the current working directory you will have to run those commands:</p><pre># <strong>Build </strong>the docker image<br>docker build . --tag=my-registry-name<br># <strong>Run </strong>the image<br>docker run -d -p 5000:5000 my-registry-name</pre><p>And you are done!</p><p>You can now push and pull images from the docker registry and have all saved in minio, you can try deleting &amp; recreating the running registry container and see that the pushed images will be still there :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9c72c72cc87" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>