N4S4 / synology-api

A Python wrapper around Synology API
MIT License
360 stars 137 forks source link

Add error details for PhotosError exception #151

Closed fdenivac closed 5 months ago

fdenivac commented 5 months ago

Hi, Synology Photos API can returns, in addition to error code, some details in json format : { "error": { "code":120, "errors": { "name":"sort_by", "reason":"condition" } }, "success":false }

This PR propose to return error details in PhotosError exception.

The photos2.py file is a new implementation of the Photo class, originally based on photos.py, refactored, completed and finally renamed for avoid API breaks. In fact, it is not necessary to add this file in synology-api (it is already included in my project https://github.com/fdenivac/synology-photos-explorer), but I don't know how to remove it from this PR! (idem for .gitignore)

For a quick test with standard API : import os from dotenv import load_dotenv from synology_api.photos import Photos from synology_api.exceptions import PhotosError

# take environment variables from .env file
load_dotenv()
foto = Photos(
            os.environ.get("SYNO_ADDR"),
            os.environ.get("SYNO_PORT"),
            os.environ.get("SYNO_USER"),
            os.environ.get("SYNO_PASSWORD"),
            secure=False,
            cert_verify=False,
            dsm_version=7,
            debug=False,
            otp_code=None,
        )
try:
    foto.list_folders(0, limit=10000)
except PhotosError as _e:
    print(_e)
try:
    foto.list_folders(0, additional="NOTEXIST")
except PhotosError as _e:
    print(_e)
N4S4 commented 5 months ago

Hello. Thank you for the PR ill try to see if i can remove photo2. That is a great find and help!

N4S4 commented 5 months ago

did you create a PR with desktop app or web?

fdenivac commented 5 months ago

Hi, this PR was created with Visual Studio Code on Windows. But, why this question ? Is it a problem ?Le 13 mars 2024 à 23:21, Renato @.***> a écrit : did you create a PR with desktop app or web?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

N4S4 commented 5 months ago

Hi, I was just asking because i was trying to remove the files that u mentioned from the PR but I can't manage. But let me investigate further

fdenivac commented 5 months ago

Hi, I was just asking because i was trying to remove the files that u mentioned from the PR but I can't manage. But let me investigate further

I'm sorry to give you so much work. But I see 2 solutions: 1- leave the photos2.py file in the project, I have no problem with that. I suggested this just to avoid 2 different implementations of the photos API in the same project, but why not? 2- reject/ignore this PR, and I can send you a patch file based on a diff of the latest version of synology-api and mine

N4S4 commented 5 months ago

I will delete this PR as is now broken, if you can PR again would be great thank you