Giter VIP home page Giter VIP logo

Comments (12)

jhtimmins avatar jhtimmins commented on June 3, 2024 1

@coderholic @scofield-ua I'll take a look later today and will fix/close this issue.

from php.

rvalitov avatar rvalitov commented on June 3, 2024 1

@jhtimmins
A function definition must include all uncatched exceptions. The exceptions may rise inside the function code or inside other functions that your original function calls. The functions that you call use Guzzle, and Guzzle functions throw \GuzzleHttp\Exception\GuzzleException. You don't catch exceptions from Guzzle therefore you pass them to the user. As a result you have to specify the \GuzzleHttp\Exception\GuzzleException in the PHPDoc.

from php.

jhtimmins avatar jhtimmins commented on June 3, 2024 1

This was fixed in commit 6068f65.

I've added an IPinfoException class which will get returned instead of the base Exception class or the GuzzleException class.

from php.

rvalitov avatar rvalitov commented on June 3, 2024

Add in PHPDoc that the function may rise an Exception

from php.

scofield-ua avatar scofield-ua commented on June 3, 2024

@coderholic

from php.

coderholic avatar coderholic commented on June 3, 2024

@jhtimmins

from php.

jhtimmins avatar jhtimmins commented on June 3, 2024

@scofield-ua my apologies, I ran into some issues with my computer so I'm having trouble testing this, which may delay me a bit.

In the meantime, could you clarify why it's necessary to import Exceptions from multiple locations?

from php.

scofield-ua avatar scofield-ua commented on June 3, 2024

@jhtimmins no problem, thanks.

I think the main idea of this issue is to fix the part where you're throwing global Exception class. For example here:

php/src/IPinfo.php

Lines 98 to 100 in 5b360e3

throw new Exception('IPinfo request quota exceeded.');
} elseif ($response->getStatusCode() >= 400) {
throw new Exception('Exception: ' . json_encode([

Right now global Exception class is throwing in local namespace: ipinfo\ipinfo, which is causing fatal error.
Need to use throw new \Exception instead of throw new Exception, or just connect it at the beginning of the class.

In my project I'm currently have to catch Throwable exception.

Also, I think, instead of general global Exception class would be good to throw some custom named exception which is related only for IpInfo package, something like IpInfoException which you can use to throw any kind (or specific kind) of errors.

from php.

rvalitov avatar rvalitov commented on June 3, 2024

@jhtimmins, the comment of @scofield-ua is absolutely correct. That's what have been done in my PR #5
Additionally I added the correct information about the exceptions in PHPDoc.

from php.

jhtimmins avatar jhtimmins commented on June 3, 2024

@scofield-ua Ah of course, yes that makes sense. I actually thought you submitted the PR with multiple exception types, which should have been directed at the PR author. Thanks for the info.

@rvalitov Could you explain this docblock, and why it includes two exception types?

     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \Exception

It doesn't look like \GuzzleHttp\Exception\GuzzleException will ever get thrown directly. Or am I missing something?

from php.

Acrash79 avatar Acrash79 commented on June 3, 2024

😊

from php.

UmanShahzad avatar UmanShahzad commented on June 3, 2024

If 6068f65 does not resolve this issue, please let me know and we can reopen.

from php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.