Coder Social home page Coder Social logo

canvas-api's People

Contributors

delodax avatar dependabot[bot] avatar exacs avatar jhsware avatar kaj avatar lenaar avatar maxhaase avatar me97esn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

canvas-api's Issues

`list()` should return promise of got `Response`

I originally opened an issue about this in my org's project repo (see tl-its-umich-edu/canvas-course-manager-next#159) because I thought we were not using KTH/canvas-api correctly. However, a colleague pointed out to me that your code is responsible for the response handling, so I'm opening this new issue.

When a Canvas API function is called without pagination handling via get(), the got Response object that was returned had a statusCode. It seems that this list() method doesn't return that type of object, so that property (and others that may be useful) isn't available.

Also, it seems to me that list() should return a promise for a got Response object (or array of them) and the toArray() method could be called later to make an array of data from those responses.

For example, I'd expect to use it something like this…

      const response = await requestor.list<CanvasCourseSection>(endpoint, queryParams)
      logger.debug(`Received response with status code ${response.statusCode}`)
      const sections = response.toArray().map(s => ({
      …

(Apologies in advance for my typos. TypeScript syntax is new to me.)

Would be nice to pass err.code to new error object

constructor(gotError: HTTPError) {

class CanvasApiError extends Error {
    constructor(gotError) {
        super(gotError.message);
        this.name = "CanvasApiError";
        this.code = gotError.code; //  <--- suggestion
        this.options = {
            headers: gotError.options.headers,
            url: gotError.options.url.toString(),
        };
        this.response = gotError.response;
        this.options.headers.authorization = "[HIDDEN]";
    }
}

Right now we don't get much discrimination between types of errors. Using the message feels brittle.

Minor export/typing issue in `3.3.0-1` pre-release?

Hi @kth/canvas-api team! Let me preface this issue by saying my team at the University of Michigan has been using your library, and has thus far found it quite useful. I hope you see me filing this issue more as a contribution than a complaint.

I've been working on some dependency updates, and I saw in a few of your pre-releases that you are making the switch to TypeScript, which is great for us since the project we're utilizing this library in is all TypeScript. However, when trying to adopt 3.3.0-1, I encountered an issue where I couldn't use error instanceof CanvasApiError (it returned an error saying "Right-hand side of 'instanceof' is not an object"), which is important to our use case. Note that I did not have this problem with the 4.0.0-0 pre-release, so I looked at the difference to see what might have changed: v4.0.0-0...v3.3.0-1 . I believe the module.exports = CanvasApi at the bottom may be the culprit, but I am not an expert on exports/modules in JS/TS.

I saw that your test is passing when CanvasApiError is imported from ./utils (it also works for me in our project if we import from @kth/canvas-api/dist/utils), but I think the intention was for this to be available from the root (since it's re-exported in index.ts). If you modify your test to import from ./index.ts, you can reproduce the problem.

+++ b/src/errorHandler.test.ts
@@ -1,6 +1,5 @@
 import createTestServer from "create-test-server";
-import Canvas from "./index";
-import { CanvasApiError } from "./utils";
+import Canvas, { CanvasApiError } from "./index";

 test("errorHandler converts HTTPError to CanvasApiError", async () => {
   const server = await createTestServer();
@@ -13,6 +12,8 @@ test("errorHandler converts HTTPError to CanvasApiError", async () => {
   try {
     await canvas.get("something");
   } catch (err) {
+    console.log(err.constructor.name);
+    console.log(typeof CanvasApiError);
     expect(err).toBeInstanceOf(CanvasApiError);
     expect(err).toMatchInlineSnapshot(
       `[CanvasApiError: Response code 401 (Unauthorized)]`
(END)

If you're open to contributions, I can open a PR against ts-compat with this commit: ssciolla@7f5c0e7

Anyways, hope that is helpful. Do you have plans to release 4.0.0 (not a pre-release) in the near future? Thanks for sharing this project!

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.